Skip to content

Commit

Permalink
add findBy() support
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Mar 6, 2024
1 parent 29f151a commit 8aa55fc
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\NodeFinder;
use PHPStan\PhpDocParser\Ast\PhpDoc\ExtendsTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\Type\ObjectType;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand All @@ -30,6 +33,7 @@ final class ChildDoctrineRepositoryClassTypeRector extends AbstractRector
public function __construct(
private readonly PhpDocInfoFactory $phpDocInfoFactory,
private readonly NodeFinder $nodeFinder,
private readonly DocBlockUpdater $docBlockUpdater
) {
}

Expand Down Expand Up @@ -110,6 +114,13 @@ public function refactor(Node $node): ?Node
if ($this->containsMethodCallNamed($classMethod, 'findBy')) {
$classMethod->returnType = new Identifier('array');
// add docblock with type

$classMethodPhpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);

$arrayTypeNode = new ArrayTypeNode(new IdentifierTypeNode($entityClassName));
$classMethodPhpDocInfo->addTagValueNode(new ReturnTagValueNode($arrayTypeNode, ''));

$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($classMethod);
}

$hasChanged = true;
Expand Down

0 comments on commit 8aa55fc

Please sign in to comment.