diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromGetRepositoryDocblockRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromGetRepositoryDocblockRector.php index b02fd6b2e4e..cb0c6e85f25 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromGetRepositoryDocblockRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromGetRepositoryDocblockRector.php @@ -4,6 +4,7 @@ namespace Rector\TypeDeclaration\Rector\ClassMethod; +use PhpParser\Comment\Doc; use PhpParser\Node; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\MethodCall; @@ -101,6 +102,11 @@ public function refactor(Node $node): ?Node return null; } + // the native type is read from the @return docblock; skip before scope fetch when there is none + if (!$node->getDocComment() instanceof Doc) { + return null; + } + if (! $this->isGetRepositoryReturnOnly($node)) { return null; }