From e08cff95e38e32994eeae45f2e0e53e2baf63b3d Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 19 Dec 2025 22:40:57 +0700 Subject: [PATCH 1/2] [Php80] Skip different type param and property type on ClassPropertyAssignToConstructorPromotionRector --- ...erent_type_property_and_param_type.php.inc | 19 +++++++++++++++++++ .../PromotedPropertyCandidateResolver.php | 7 +++++++ 2 files changed, 26 insertions(+) create mode 100644 rules-tests/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector/Fixture/skip_different_type_property_and_param_type.php.inc diff --git a/rules-tests/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector/Fixture/skip_different_type_property_and_param_type.php.inc b/rules-tests/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector/Fixture/skip_different_type_property_and_param_type.php.inc new file mode 100644 index 00000000000..c413acb61a3 --- /dev/null +++ b/rules-tests/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector/Fixture/skip_different_type_property_and_param_type.php.inc @@ -0,0 +1,19 @@ +customerInput = $customerInput; + } + + public function markResolved(): void + { + $this->customerInput = null; + } +} diff --git a/rules/Php80/NodeAnalyzer/PromotedPropertyCandidateResolver.php b/rules/Php80/NodeAnalyzer/PromotedPropertyCandidateResolver.php index 5956e0a715f..dc1c6161da6 100644 --- a/rules/Php80/NodeAnalyzer/PromotedPropertyCandidateResolver.php +++ b/rules/Php80/NodeAnalyzer/PromotedPropertyCandidateResolver.php @@ -5,6 +5,7 @@ namespace Rector\Php80\NodeAnalyzer; use PhpParser\Node; +use PhpParser\Node\Expr; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\Variable; @@ -131,6 +132,12 @@ private function matchPropertyPromotionCandidate( continue; } + if ($property->type instanceof Node + && ! $matchedParam->default instanceof Expr + && ! $this->nodeComparator->areNodesEqual($matchedParam->type, $property->type)) { + continue; + } + if ($this->shouldSkipParam($matchedParam, $assignedExpr, $firstParamAsVariable)) { continue; } From e4f44c00f9da2e7570a7cc39ef978491fd0deacf Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 19 Dec 2025 22:45:32 +0700 Subject: [PATCH 2/2] fix test --- rules/Php80/NodeAnalyzer/PromotedPropertyCandidateResolver.php | 1 + 1 file changed, 1 insertion(+) diff --git a/rules/Php80/NodeAnalyzer/PromotedPropertyCandidateResolver.php b/rules/Php80/NodeAnalyzer/PromotedPropertyCandidateResolver.php index dc1c6161da6..2a6c7b8164c 100644 --- a/rules/Php80/NodeAnalyzer/PromotedPropertyCandidateResolver.php +++ b/rules/Php80/NodeAnalyzer/PromotedPropertyCandidateResolver.php @@ -133,6 +133,7 @@ private function matchPropertyPromotionCandidate( } if ($property->type instanceof Node + && $matchedParam->type instanceof Node && ! $matchedParam->default instanceof Expr && ! $this->nodeComparator->areNodesEqual($matchedParam->type, $property->type)) { continue;