diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_this_return_in_trait.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_this_return_in_trait.php.inc new file mode 100644 index 00000000000..a25261cddc3 --- /dev/null +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_this_return_in_trait.php.inc @@ -0,0 +1,16 @@ +isClassTypeAlias($node, $returnTagValueNode)) { + $scope = ScopeFetcher::fetch($node); + if ($this->isClassTypeAlias($scope, $returnTagValueNode)) { return null; } $nativeReturnType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($node->returnType); + $classReflection = $scope->getClassReflection(); + if ($classReflection instanceof ClassReflection && $classReflection->isTrait() + && $returnTagValueNode->type instanceof ThisTypeNode + && $nativeReturnType instanceof ObjectType + ) { + return null; + } + if ($this->isReturnTemplate($phpDocInfo, $returnTagValueNode)) { return null; } @@ -134,10 +146,9 @@ public function refactor(Node $node): ?Node return $node; } - private function isClassTypeAlias(Node $node, ReturnTagValueNode $returnTagValueNode): bool + private function isClassTypeAlias(Scope $scope, ReturnTagValueNode $returnTagValueNode): bool { - $scope = $node->getAttribute(AttributeKey::SCOPE); - if (! $scope instanceof Scope || ! $scope->isInClass()) { + if (! $scope->isInClass()) { return false; }