From 598e5d383f37113e9f41cda3d7f0b3f6ed81e783 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 2 Jan 2026 20:39:24 +0100 Subject: [PATCH 1/2] applyps --- src/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 { From 6cce3789251589156421397a71d391b176206097 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 2 Jan 2026 20:59:34 +0100 Subject: [PATCH 2/2] skip connection calls in AddReturnDocblockFromMethodCallDocblockRector --- .../Fixture/skip_fetch_first_column.php.inc | 22 +++++++++++++++++++ ...rnDocblockFromMethodCallDocblockRector.php | 12 ++++++++++ stubs/Doctrine/DBAL/Connection.php | 16 ++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockFromMethodCallDocblockRector/Fixture/skip_fetch_first_column.php.inc create mode 100644 stubs/Doctrine/DBAL/Connection.php 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/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 []; + } +}