-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapt PrivateConstantToSelfRector to work on non-final classes, too (#…
…3198) * Adapt PrivateConstantToSelfRector to work on non-final classes, too * Update rules/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector.php Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com> * Update rules/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector.php Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com> Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
- Loading branch information
1 parent
14e60b0
commit 21c9e59
Showing
8 changed files
with
275 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...teConstantToSelfRector/ConvertStaticPrivateConstantToSelfRectorForNonFinalClassesTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\ClassConstFetch\ConvertStaticPrivateConstantToSelfRector; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class ConvertStaticPrivateConstantToSelfRectorForNonFinalClassesTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
/** | ||
* @return Iterator<array<string>> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureEnableForNonFinalClasses'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/config_non_final_classes.php'; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...Fetch/ConvertStaticPrivateConstantToSelfRector/Fixture/replace-in-private-methods.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Utils\Rector\Tests\Rector\UseDateTimeImmutableRector\Fixture; | ||
|
||
class Foo | ||
{ | ||
private const BAR = 1; | ||
private function baz(): void | ||
{ | ||
echo static::BAR; | ||
} | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Utils\Rector\Tests\Rector\UseDateTimeImmutableRector\Fixture; | ||
|
||
class Foo | ||
{ | ||
private const BAR = 1; | ||
private function baz(): void | ||
{ | ||
echo self::BAR; | ||
} | ||
} | ||
?> |
18 changes: 18 additions & 0 deletions
18
...tureEnableForNonFinalClasses/do-not-replace-if-used-in-child-classes-as-protected.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Utils\Rector\Tests\Rector\UseDateTimeImmutableRector\Fixture; | ||
|
||
class ParentClass2 | ||
{ | ||
private const BAR2 = 1; | ||
public function baz(): void | ||
{ | ||
echo static::BAR2; | ||
} | ||
} | ||
|
||
class ChildClass2 extends ParentClass2 { | ||
protected const BAR2 = 2; | ||
} | ||
|
||
?> |
18 changes: 18 additions & 0 deletions
18
...FixtureEnableForNonFinalClasses/do-not-replace-if-used-in-child-classes-as-public.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Utils\Rector\Tests\Rector\UseDateTimeImmutableRector\Fixture; | ||
|
||
class ParentClass3 | ||
{ | ||
private const BAR3 = 1; | ||
public function baz(): void | ||
{ | ||
echo static::BAR3; | ||
} | ||
} | ||
|
||
class ChildClass3 extends ParentClass3 { | ||
public const BAR3 = 2; | ||
} | ||
|
||
?> |
33 changes: 33 additions & 0 deletions
33
...ToSelfRector/FixtureEnableForNonFinalClasses/replace-if-not-used-in-child-classes.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Utils\Rector\Tests\Rector\UseDateTimeImmutableRector\Fixture; | ||
|
||
class ParentClass1 | ||
{ | ||
private const BAR1 = 1; | ||
public function baz(): void | ||
{ | ||
echo static::BAR1; | ||
} | ||
} | ||
|
||
class ChildClass1 extends ParentClass1 {} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Utils\Rector\Tests\Rector\UseDateTimeImmutableRector\Fixture; | ||
|
||
class ParentClass1 | ||
{ | ||
private const BAR1 = 1; | ||
public function baz(): void | ||
{ | ||
echo self::BAR1; | ||
} | ||
} | ||
|
||
class ChildClass1 extends ParentClass1 {} | ||
|
||
?> |
16 changes: 16 additions & 0 deletions
16
...ssConstFetch/ConvertStaticPrivateConstantToSelfRector/config/config_non_final_classes.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\CodeQuality\Rector\ClassConstFetch\ConvertStaticPrivateConstantToSelfRector; | ||
use Rector\Config\RectorConfig; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig | ||
->ruleWithConfiguration( | ||
ConvertStaticPrivateConstantToSelfRector::class, | ||
[ | ||
ConvertStaticPrivateConstantToSelfRector::ENABLE_FOR_NON_FINAL_CLASSES => true, | ||
] | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters