Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddReturnDocblockFromMethodCallDocblockRector\Fixture;

use Doctrine\DBAL\Connection;

final class SkipFetchFirstColumn
{
private Connection $connection;

public function __construct(Connection $connection)
{
$this->connection = $connection;
}

public function getAll(): array
{
return $this->connection->fetchFirstColumn();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function getOriginalPhpDocNode(): PhpDocNode
}

/**
* @return mixed[]
* @return list<array{string, int, int}>
*/
public function getTokens(): array
{
Expand Down
16 changes: 16 additions & 0 deletions stubs/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL;

final class Connection
{
/**
* @return list<mixed>
*/
public function fetchFirstColumn(string $query, array $params = [], array $types = []): array
{
return [];
}
}