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..2a6c7b8164c 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,13 @@ private function matchPropertyPromotionCandidate( continue; } + if ($property->type instanceof Node + && $matchedParam->type instanceof Node + && ! $matchedParam->default instanceof Expr + && ! $this->nodeComparator->areNodesEqual($matchedParam->type, $property->type)) { + continue; + } + if ($this->shouldSkipParam($matchedParam, $assignedExpr, $firstParamAsVariable)) { continue; }