-
-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add an option to skip renaming promoted property (#5457)
* feat: add an option to skip renaming promoted property * fix: update code sample * fix: update code sample * feat: add generic test case
- Loading branch information
1 parent
f24b01a
commit ac072bc
Showing
5 changed files
with
116 additions
and
6 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
..._/ClassPropertyAssignToConstructorPromotionRector/FixtureRenamingDisabled/fixture.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,35 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\Fixture; | ||
|
||
class Fixture | ||
{ | ||
public float $x; | ||
public float $y; | ||
public float $z; | ||
|
||
public function __construct( | ||
float $x = 0.0, | ||
float $y = 0.0, | ||
float $z = 0.0 | ||
) { | ||
$this->x = $x; | ||
$this->y = $y; | ||
$this->z = $z; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\Fixture; | ||
|
||
class Fixture | ||
{ | ||
public function __construct(public float $x = 0.0, public float $y = 0.0, public float $z = 0.0) | ||
{ | ||
} | ||
} | ||
|
||
?> |
18 changes: 18 additions & 0 deletions
18
...ssignToConstructorPromotionRector/FixtureRenamingDisabled/skip_if_different_names.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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\Fixture; | ||
|
||
use Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\Source\Fixer; | ||
use Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\Source\SkipParentPublic as BaseSkipParentPublic; | ||
|
||
final class SkipWhenNameIsDifferent | ||
{ | ||
private Fixer $fixer; | ||
|
||
public function __construct(Fixer $notSameName) | ||
{ | ||
$this->fixer = $notSameName; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...tor/Class_/ClassPropertyAssignToConstructorPromotionRector/RenamePropertyDisabledTest.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\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class RenamePropertyDisabledTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/FixtureRenamingDisabled'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule_disabled_renaming.php'; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...ssPropertyAssignToConstructorPromotionRector/config/configured_rule_disabled_renaming.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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->ruleWithConfiguration(ClassPropertyAssignToConstructorPromotionRector::class, [ | ||
ClassPropertyAssignToConstructorPromotionRector::RENAME_PROPERTY => false, | ||
]); | ||
}; |
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