diff --git a/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockFromMethodCallDocblockRector/Fixture/skip_fetch_first_column.php.inc b/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockFromMethodCallDocblockRector/Fixture/skip_fetch_first_column.php.inc new file mode 100644 index 00000000000..c5c35022334 --- /dev/null +++ b/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockFromMethodCallDocblockRector/Fixture/skip_fetch_first_column.php.inc @@ -0,0 +1,22 @@ +connection = $connection; + } + + public function getAll(): array + { + return $this->connection->fetchFirstColumn(); + } +} diff --git a/rules/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockFromMethodCallDocblockRector.php b/rules/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockFromMethodCallDocblockRector.php index 460cf7f53ce..2fb69f1a066 100644 --- a/rules/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockFromMethodCallDocblockRector.php +++ b/rules/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockFromMethodCallDocblockRector.php @@ -10,8 +10,10 @@ use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Return_; use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode; +use PHPStan\Type\ObjectType; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger; +use Rector\Doctrine\Enum\DoctrineClass; use Rector\PhpParser\AstResolver; use Rector\Rector\AbstractRector; use Rector\TypeDeclarationDocblocks\NodeFinder\ReturnNodeFinder; @@ -120,6 +122,12 @@ public function refactor(Node $node): ?Node $returnedMethodCall = $onlyReturnWithExpr->expr; + // skip doctrine connection calls, as to generic and not helpful + $callerType = $this->getType($returnedMethodCall->var); + if ($callerType instanceof ObjectType && $callerType->isInstanceOf(DoctrineClass::CONNECTION)->yes()) { + return null; + } + $calledClassMethod = $this->astResolver->resolveClassMethodFromCall($returnedMethodCall); if (! $calledClassMethod instanceof ClassMethod) { return null; @@ -140,6 +148,10 @@ public function refactor(Node $node): ?Node return null; } + if (! $this->usefulArrayTagNodeAnalyzer->isUsefulArrayTag($calledReturnTagValue)) { + return null; + } + $this->phpDocTypeChanger->changeReturnTypeNode($node, $phpDocInfo, $calledReturnTagValue->type); return $node; diff --git a/src/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php b/src/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php index a601b72c306..6bf45874b6a 100644 --- a/src/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php +++ b/src/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php @@ -94,7 +94,7 @@ public function getOriginalPhpDocNode(): PhpDocNode } /** - * @return mixed[] + * @return list */ public function getTokens(): array { diff --git a/stubs/Doctrine/DBAL/Connection.php b/stubs/Doctrine/DBAL/Connection.php new file mode 100644 index 00000000000..3b911fc49d2 --- /dev/null +++ b/stubs/Doctrine/DBAL/Connection.php @@ -0,0 +1,16 @@ + + */ + public function fetchFirstColumn(string $query, array $params = [], array $types = []): array + { + return []; + } +}