diff --git a/rules-tests/Php84/Rector/Class_/PropertyHookRector/Fixture/skip_mix_with_existing_readonly_promoted_property.php.inc b/rules-tests/Php84/Rector/Class_/PropertyHookRector/Fixture/skip_mix_with_existing_readonly_promoted_property.php.inc new file mode 100644 index 00000000000..9e35260873d --- /dev/null +++ b/rules-tests/Php84/Rector/Class_/PropertyHookRector/Fixture/skip_mix_with_existing_readonly_promoted_property.php.inc @@ -0,0 +1,29 @@ +name; + } + + public function setName(string $name): void + { + $this->name = ucfirst($name); + } + + public function __construct( + private readonly int $value, + ) + { + } + + public function getValue() + { + return $this->value; + } +} diff --git a/rules/Php84/NodeFinder/SetterAndGetterFinder.php b/rules/Php84/NodeFinder/SetterAndGetterFinder.php index 2adcc7f15be..1ffd6a95bf0 100644 --- a/rules/Php84/NodeFinder/SetterAndGetterFinder.php +++ b/rules/Php84/NodeFinder/SetterAndGetterFinder.php @@ -7,6 +7,7 @@ use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use Rector\TypeDeclaration\NodeAnalyzer\ClassMethodAndPropertyAnalyzer; +use Rector\ValueObject\MethodName; final readonly class SetterAndGetterFinder { @@ -22,6 +23,16 @@ public function findGetterAndSetterClassMethods(Class_ $class, string $propertyN { $classMethods = []; + $constructClassMethod = $class->getMethod(MethodName::CONSTRUCT); + + if ($constructClassMethod instanceof ClassMethod) { + foreach ($constructClassMethod->params as $param) { + if ($param->isReadonly()) { + return []; + } + } + } + $getterClassMethod = $this->findGetterClassMethod($class, $propertyName); if ($getterClassMethod instanceof ClassMethod) { $classMethods[] = $getterClassMethod;