diff --git a/rules-tests/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector/Fixture/skip_hook_with_indirect_set.php.inc b/rules-tests/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector/Fixture/skip_hook_with_indirect_set.php.inc new file mode 100644 index 00000000000..7020c733b68 --- /dev/null +++ b/rules-tests/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector/Fixture/skip_hook_with_indirect_set.php.inc @@ -0,0 +1,25 @@ +value; + } + set { + if ($this->optionUsedInValueSetter) { + $this->value = "changed value"; + } + $this->value = $value; + } + } + + public function __construct( + mixed $value, + bool $optionUsedInValueSetter = false, + ) { + $this->value = $value; + } +} \ No newline at end of file diff --git a/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php b/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php index bbea7ac7198..7d897abebc3 100644 --- a/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php +++ b/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php @@ -361,6 +361,16 @@ private function isCallableTypeIdentifier(?Node $node): bool private function shouldSkipPropertyOrParam(Property $property, Param $param): bool { + foreach ($property->hooks as $hook) { + if (! is_array($hook->body)) { + continue; + } + + if (count($hook->body) > 1) { + return true; + } + } + return $property->type instanceof Node && $param->type instanceof Node && $property->hooks !== []