diff --git a/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnVendorLockResolver.php b/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnVendorLockResolver.php index bc1e38b51e5a..92751d1cd277 100644 --- a/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnVendorLockResolver.php +++ b/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnVendorLockResolver.php @@ -11,16 +11,10 @@ use PHPStan\Type\MixedType; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\Node\AttributeKey; -use Rector\VendorLocker\Reflection\ClassReflectionAncestorAnalyzer; use Rector\VendorLocker\Reflection\MethodReflectionContractAnalyzer; final class ClassMethodReturnVendorLockResolver { - /** - * @var ClassReflectionAncestorAnalyzer - */ - private $classReflectionAncestorAnalyzer; - /** * @var MethodReflectionContractAnalyzer */ @@ -32,11 +26,9 @@ final class ClassMethodReturnVendorLockResolver private $nodeNameResolver; public function __construct( - ClassReflectionAncestorAnalyzer $classReflectionAncestorAnalyzer, MethodReflectionContractAnalyzer $methodReflectionContractAnalyzer, NodeNameResolver $nodeNameResolver ) { - $this->classReflectionAncestorAnalyzer = $classReflectionAncestorAnalyzer; $this->methodReflectionContractAnalyzer = $methodReflectionContractAnalyzer; $this->nodeNameResolver = $nodeNameResolver; } @@ -53,7 +45,7 @@ public function isVendorLocked(ClassMethod $classMethod): bool return false; } - if (! $this->classReflectionAncestorAnalyzer->hasAncestors($classReflection)) { + if (count($classReflection->getAncestors()) === 1) { return false; } diff --git a/packages/VendorLocker/NodeVendorLocker/PropertyTypeVendorLockResolver.php b/packages/VendorLocker/NodeVendorLocker/PropertyTypeVendorLockResolver.php index ab8bcf384a57..91bf4932ef4e 100644 --- a/packages/VendorLocker/NodeVendorLocker/PropertyTypeVendorLockResolver.php +++ b/packages/VendorLocker/NodeVendorLocker/PropertyTypeVendorLockResolver.php @@ -10,15 +10,9 @@ use Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\Node\AttributeKey; -use Rector\VendorLocker\Reflection\ClassReflectionAncestorAnalyzer; final class PropertyTypeVendorLockResolver { - /** - * @var ClassReflectionAncestorAnalyzer - */ - private $classReflectionAncestorAnalyzer; - /** * @var NodeNameResolver */ @@ -30,11 +24,9 @@ final class PropertyTypeVendorLockResolver private $familyRelationsAnalyzer; public function __construct( - ClassReflectionAncestorAnalyzer $classReflectionAncestorAnalyzer, NodeNameResolver $nodeNameResolver, FamilyRelationsAnalyzer $familyRelationsAnalyzer ) { - $this->classReflectionAncestorAnalyzer = $classReflectionAncestorAnalyzer; $this->nodeNameResolver = $nodeNameResolver; $this->familyRelationsAnalyzer = $familyRelationsAnalyzer; } @@ -49,7 +41,7 @@ public function isVendorLocked(Property $property): bool return false; } - if (! $this->classReflectionAncestorAnalyzer->hasAncestors($classReflection)) { + if (count($classReflection->getAncestors()) === 1) { return false; } diff --git a/packages/VendorLocker/Reflection/ClassReflectionAncestorAnalyzer.php b/packages/VendorLocker/Reflection/ClassReflectionAncestorAnalyzer.php deleted file mode 100644 index 50440b7db471..000000000000 --- a/packages/VendorLocker/Reflection/ClassReflectionAncestorAnalyzer.php +++ /dev/null @@ -1,15 +0,0 @@ -getAncestors() !== [$classReflection]; - } -} diff --git a/rules-tests/TypeDeclaration/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/skip_already_set_return_type.php.inc b/rules-tests/TypeDeclaration/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/skip_already_set_return_type.php.inc new file mode 100644 index 000000000000..585c6195aa95 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/skip_already_set_return_type.php.inc @@ -0,0 +1,21 @@ +getAttribute(AttributeKey::SCOPE); + if (! $scope instanceof Scope) { + return false; + } - return $scope->hasVariableType($variableName) - ->yes(); + return $scope->hasVariableType($variableName)->yes(); } }