Skip to content

[NodeAnalyzer] Detect Doctrine static function mapping (loadMetadata) entity in DoctrineEntityDetector#484

Merged
TomasVotruba merged 3 commits into
mainfrom
tv-skip-static-mapping
Jun 20, 2026
Merged

[NodeAnalyzer] Detect Doctrine static function mapping (loadMetadata) entity in DoctrineEntityDetector#484
TomasVotruba merged 3 commits into
mainfrom
tv-skip-static-mapping

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Recognize Doctrine static function mapping classes as entities in DoctrineEntityDetector.

Such classes map their fields in a loadMetadata() method instead of attributes/annotations, so the existing annotation + attribute detection misses them. The detector now also treats a class defining a loadMetadata() method as a Doctrine entity. The cheap, pure-AST check runs first.

Example

use Doctrine\ORM\Mapping\ClassMetadata;

final class Product
{
    private $name;

    public static function loadMetadata(ClassMetadata $metadata): void
    {
        $metadata->mapField([
            'fieldName' => 'name',
            'type' => 'string',
        ]);
    }
}

Product is a Doctrine entity even without any annotation or attribute, so DoctrineEntityDetector::detect() now returns true for it.

Mirrors rectorphp/rector-src#8059, which skips such classes in TypedPropertyFromAssignsRector and RemoveUnusedPrivatePropertyRector.

@TomasVotruba TomasVotruba merged commit 9932c71 into main Jun 20, 2026
8 checks passed
@TomasVotruba TomasVotruba deleted the tv-skip-static-mapping branch June 20, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants