From 4fa5ea5a8f4b17af311b8cf13da8173c0bb210bf Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 4 Sep 2023 09:40:16 +0700 Subject: [PATCH 1/3] [TypeDeclaration] Skip mixing native + docblock union assign on TypedPropertyFromAssignsRector --- ...p_mixed_native_with_docblock_union.php.inc | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector/Fixture/skip_mixed_native_with_docblock_union.php.inc diff --git a/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector/Fixture/skip_mixed_native_with_docblock_union.php.inc b/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector/Fixture/skip_mixed_native_with_docblock_union.php.inc new file mode 100644 index 00000000000..94078268582 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector/Fixture/skip_mixed_native_with_docblock_union.php.inc @@ -0,0 +1,24 @@ +property = new stdClass; + } + + /** + * @param stdClass|DateTime $property + */ + public function run2($property) + { + $this->property = $property; + } +} From d5b73f0d94f60d5009bf25afb2dc7c4462047949 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 4 Sep 2023 09:40:44 +0700 Subject: [PATCH 2/3] Fixed :tada: --- .../TypeInferer/AssignToPropertyTypeInferer.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rules/TypeDeclaration/TypeInferer/AssignToPropertyTypeInferer.php b/rules/TypeDeclaration/TypeInferer/AssignToPropertyTypeInferer.php index 7965caa6ad8..d7bd0a629e7 100644 --- a/rules/TypeDeclaration/TypeInferer/AssignToPropertyTypeInferer.php +++ b/rules/TypeDeclaration/TypeInferer/AssignToPropertyTypeInferer.php @@ -198,6 +198,9 @@ private function getAssignedExprTypes(ClassLike $classLike, string $propertyName } if ($this->exprAnalyzer->isNonTypedFromParam($node->expr)) { + $assignedExprTypes = []; + return NodeTraverser::STOP_TRAVERSAL; + return null; } From 91f7c5608c5b1bac12d5c658fb9683f0a3c6364e Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Mon, 4 Sep 2023 02:42:33 +0000 Subject: [PATCH 3/3] [ci-review] Rector Rectify --- .../TypeDeclaration/TypeInferer/AssignToPropertyTypeInferer.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/rules/TypeDeclaration/TypeInferer/AssignToPropertyTypeInferer.php b/rules/TypeDeclaration/TypeInferer/AssignToPropertyTypeInferer.php index d7bd0a629e7..e47471e87d4 100644 --- a/rules/TypeDeclaration/TypeInferer/AssignToPropertyTypeInferer.php +++ b/rules/TypeDeclaration/TypeInferer/AssignToPropertyTypeInferer.php @@ -200,8 +200,6 @@ private function getAssignedExprTypes(ClassLike $classLike, string $propertyName if ($this->exprAnalyzer->isNonTypedFromParam($node->expr)) { $assignedExprTypes = []; return NodeTraverser::STOP_TRAVERSAL; - - return null; } $assignedExprTypes[] = $this->resolveExprStaticTypeIncludingDimFetch($node);