-
-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Privatization][TypeDeclaration] Do not replace non-readonly property…
… to constant on ChangeReadOnlyPropertyWithDefaultValueToConstantRector+TypedPropertyFromAssignsRector (#3891) * [Privatization][TypeDeclaration] Do not replace non-readonly property to constant on ChangeReadOnlyPropertyWithDefaultValueToConstantRector+TypedPropertyFromAssignsRector * eol * add missing namespace * Fixed 🎉 * clean up * increase kernel cache key
- Loading branch information
1 parent
af2a06e
commit 9cfeac0
Showing
6 changed files
with
106 additions
and
9 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
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
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
28 changes: 28 additions & 0 deletions
28
...NotReplaceNonReadonlyPropertyToConstant/DoNotReplaceNonReadonlyPropertyToConstantTest.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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\DoNotReplaceNonReadonlyPropertyToConstant; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class DoNotReplaceNonReadonlyPropertyToConstantTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
tests/Issues/DoNotReplaceNonReadonlyPropertyToConstant/Fixture/change_only_type.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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\DoNotReplaceNonReadonlyPropertyToConstant\Fixture; | ||
|
||
final class ChangeOnlyType | ||
{ | ||
/** @var string|null */ | ||
private static $defaultFilesHash; | ||
|
||
/** | ||
* @param string[] $configFiles | ||
*/ | ||
public function run(array $configFiles): string | ||
{ | ||
if (self::$defaultFilesHash === null) { | ||
self::$defaultFilesHash = 'test'; | ||
} | ||
|
||
return self::$defaultFilesHash . 'test 2'; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\DoNotReplaceNonReadonlyPropertyToConstant\Fixture; | ||
|
||
final class ChangeOnlyType | ||
{ | ||
private static ?string $defaultFilesHash = null; | ||
|
||
/** | ||
* @param string[] $configFiles | ||
*/ | ||
public function run(array $configFiles): string | ||
{ | ||
if (self::$defaultFilesHash === null) { | ||
self::$defaultFilesHash = 'test'; | ||
} | ||
|
||
return self::$defaultFilesHash . 'test 2'; | ||
} | ||
} | ||
|
||
?> |
14 changes: 14 additions & 0 deletions
14
tests/Issues/DoNotReplaceNonReadonlyPropertyToConstant/config/configured_rule.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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Privatization\Rector\Property\ChangeReadOnlyPropertyWithDefaultValueToConstantRector; | ||
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rules([ | ||
ChangeReadOnlyPropertyWithDefaultValueToConstantRector::class, | ||
TypedPropertyFromAssignsRector::class, | ||
]); | ||
}; |