Skip to content

Commit 98d0a5b

Browse files
committed
feat: add StaticToSelfStaticPropertyFetchOnFinalClassRector
1 parent ab29a4a commit 98d0a5b

File tree

13 files changed

+333
-0
lines changed

13 files changed

+333
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodeQuality\Rector\Class_\StaticToSelfStaticPropertyFetchOnFinalClassRector\Fixture;
4+
5+
final class BasicPropertyFetch
6+
{
7+
private static $someProperty = 'value';
8+
9+
public function test()
10+
{
11+
return static::$someProperty;
12+
}
13+
}
14+
15+
?>
16+
-----
17+
<?php
18+
19+
namespace Rector\Tests\CodeQuality\Rector\Class_\StaticToSelfStaticPropertyFetchOnFinalClassRector\Fixture;
20+
21+
final class BasicPropertyFetch
22+
{
23+
private static $someProperty = 'value';
24+
25+
public function test()
26+
{
27+
return self::$someProperty;
28+
}
29+
}
30+
31+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodeQuality\Rector\Class_\StaticToSelfStaticPropertyFetchOnFinalClassRector\Fixture;
4+
5+
final class MultipleProperties
6+
{
7+
private static $property1 = 'value1';
8+
protected static $property2 = 'value2';
9+
public static $property3 = 'value3';
10+
11+
public function getValues()
12+
{
13+
return [
14+
static::$property1,
15+
static::$property2,
16+
static::$property3,
17+
];
18+
}
19+
}
20+
21+
?>
22+
-----
23+
<?php
24+
25+
namespace Rector\Tests\CodeQuality\Rector\Class_\StaticToSelfStaticPropertyFetchOnFinalClassRector\Fixture;
26+
27+
final class MultipleProperties
28+
{
29+
private static $property1 = 'value1';
30+
protected static $property2 = 'value2';
31+
public static $property3 = 'value3';
32+
33+
public function getValues()
34+
{
35+
return [
36+
self::$property1,
37+
self::$property2,
38+
self::$property3,
39+
];
40+
}
41+
}
42+
43+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodeQuality\Rector\Class_\StaticToSelfStaticPropertyFetchOnFinalClassRector\Fixture;
4+
5+
use Rector\Tests\CodeQuality\Rector\Class_\StaticToSelfStaticPropertyFetchOnFinalClassRector\Source\BaseClass;
6+
7+
final class ParentStaticProperty extends BaseClass
8+
{
9+
public function test(): string
10+
{
11+
return static::$parentProperty;
12+
}
13+
}
14+
15+
?>
16+
-----
17+
<?php
18+
19+
namespace Rector\Tests\CodeQuality\Rector\Class_\StaticToSelfStaticPropertyFetchOnFinalClassRector\Fixture;
20+
21+
use Rector\Tests\CodeQuality\Rector\Class_\StaticToSelfStaticPropertyFetchOnFinalClassRector\Source\BaseClass;
22+
23+
final class ParentStaticProperty extends BaseClass
24+
{
25+
public function test(): string
26+
{
27+
return self::$parentProperty;
28+
}
29+
}
30+
31+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodeQuality\Rector\Class_\StaticToSelfStaticPropertyFetchOnFinalClassRector\Fixture;
4+
5+
final class SkipAlreadySelf
6+
{
7+
private static $someProperty = 'value';
8+
9+
public function getValue()
10+
{
11+
return self::$someProperty;
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodeQuality\Rector\Class_\StaticToSelfStaticPropertyFetchOnFinalClassRector\Fixture;
4+
5+
final class SkipDynamicProperty
6+
{
7+
public function getValue($propertyName)
8+
{
9+
return static::$$propertyName;
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodeQuality\Rector\Class_\StaticToSelfStaticPropertyFetchOnFinalClassRector\Fixture;
4+
5+
final class SkipNonExistingProperty
6+
{
7+
public function getValue()
8+
{
9+
return static::$nonExistingProperty;
10+
}
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodeQuality\Rector\Class_\StaticToSelfStaticPropertyFetchOnFinalClassRector\Fixture;
4+
5+
class SkipNonFinal
6+
{
7+
private static $someProperty = 'value';
8+
9+
public function getValue()
10+
{
11+
return static::$someProperty;
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodeQuality\Rector\Class_\StaticToSelfStaticPropertyFetchOnFinalClassRector\Fixture;
4+
5+
final class SkipNonStaticProperty
6+
{
7+
private $someProperty = 'value';
8+
9+
public function getValue()
10+
{
11+
return static::$someProperty;
12+
}
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodeQuality\Rector\Class_\StaticToSelfStaticPropertyFetchOnFinalClassRector\Source;
4+
5+
class BaseClass
6+
{
7+
protected static $parentProperty = 'parent value';
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\CodeQuality\Rector\Class_\StaticToSelfStaticPropertyFetchOnFinalClassRector;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class StaticToSelfStaticPropertyFetchOnFinalClassRectorTest extends AbstractRectorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
22+
}
23+
24+
public function provideConfigFilePath(): string
25+
{
26+
return __DIR__ . '/config/configured_rule.php';
27+
}
28+
}

0 commit comments

Comments
 (0)