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
6 changes: 6 additions & 0 deletions packages/Doctrine/src/AbstractRector/DoctrineTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Rector\Doctrine\AbstractRector;

use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Property;
use Rector\Doctrine\PhpDocParser\DoctrineDocBlockResolver;
Expand Down Expand Up @@ -32,6 +33,11 @@ protected function isDoctrineEntityClass(Class_ $class): bool
return $this->doctrineDocBlockResolver->isDoctrineEntityClass($class);
}

protected function isInDoctrineEntityClass(Node $node): bool
{
return $this->doctrineDocBlockResolver->isInDoctrineEntityClass($node);
}

protected function getTargetEntity(Property $property): ?string
{
return $this->doctrineDocBlockResolver->getTargetEntity($property);
Expand Down
13 changes: 13 additions & 0 deletions packages/Doctrine/src/PhpDocParser/DoctrineDocBlockResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\Property;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Class_\EntityTagValueNode;
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\ColumnTagValueNode;
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\IdTagValueNode;
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\DoctrineRelationTagValueNodeInterface;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockManipulator;

final class DoctrineDocBlockResolver
Expand Down Expand Up @@ -97,6 +99,17 @@ public function isDoctrineProperty(Property $property): bool
return (bool) $propertyPhpDocInfo->getByType(DoctrineRelationTagValueNodeInterface::class);
}

public function isInDoctrineEntityClass(Node $node): bool
{
/** @var ClassLike|null $classNode */
$classNode = $node->getAttribute(AttributeKey::CLASS_NODE);
if (! $classNode instanceof Class_) {
return false;
}

return $this->isDoctrineEntityClass($classNode);
}

private function getPhpDocInfo(Node $node): ?PhpDocInfo
{
if ($node->getDocComment() === null) {
Expand Down