Skip to content

[composer-based] Bond data-fixtures rule and annotation-to-attribute sets to composer package constraints - #497

Merged
TomasVotruba merged 2 commits into
mainfrom
composer-based-fixtures-attributes
Aug 3, 2026
Merged

[composer-based] Bond data-fixtures rule and annotation-to-attribute sets to composer package constraints#497
TomasVotruba merged 2 commits into
mainfrom
composer-based-fixtures-attributes

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Follow-up to #495. Two gaps remained after the composer-based bonding.

1. AddGetReferenceTypeRector had no composer constraint

The rule fills the second getReference() argument, which only exists from doctrine/data-fixtures 1.6 (data-fixtures#409). The set provider already knew the version — it registers data-fixtures-16.php as a ComposerTriggeredSet at 1.6 — but the rule itself carried no ComposerPackageConstraintInterface, and unlike its data-fixtures-17 sibling it was never added to composer-based.php.

-final class AddGetReferenceTypeRector extends AbstractRector
+final class AddGetReferenceTypeRector extends AbstractRector implements ComposerPackageConstraintInterface
 {
+    public function provideComposerPackageConstraint(): ComposerPackageConstraint
+    {
+        return new ComposerPackageConstraint('doctrine/data-fixtures', '>=1.6');
+    }

What the rule does, now only on data-fixtures >= 1.6:

 final class SomeFixture extends AbstractFixture
 {
     public function run(SomeEntity $someEntity)
     {
-        $someEntity->setSomePassedEntity($this->getReference('some-id'));
+        $someEntity->setSomePassedEntity($this->getReference('some-id', SomePassedEntity::class));
     }
 }

doctrine/data-fixtures is added to require-dev so the rule test actually exercises the constraint instead of silently skipping.

2. Annotation-to-attribute sets are now composer-bound too

ANNOTATIONS_TO_ATTRIBUTES, GEDMO_ANNOTATIONS_TO_ATTRIBUTES and MONGODB_ANNOTATIONS_TO_ATTRIBUTES convert annotations to attribute classes that only exist from a specific package version. Each config block moves into composer-based.php bound to the version that first shipped those classes as PHP 8 attributes:

package version verified against
doctrine/orm >=2.9 #[Attribute] on Mapping\Entity absent in 2.8.0, present in 2.9.0
doctrine/mongodb-odm >=2.3 absent in 2.2.0, present in 2.3.0
doctrine/mongodb-odm-bundle >=4.4 Validator\Constraints\Unique absent in 4.3.0, present in 4.4.0
gedmo/doctrine-extensions >=3.5 Mapping\Annotation\Slug absent in v3.4.0, present in v3.5.0

The Unique constraint previously travelled inside the MongoDB set but belongs to a different package, so it gets its own bound.

Result on an ORM >= 2.9 project using withComposerBased():

 use Doctrine\ORM\Mapping as ORM;

-/**
- * @ORM\Entity
- */
+#[ORM\Entity]
 final class SomeEntity
 {
-    /**
-     * @ORM\Column(type="string")
-     */
+    #[ORM\Column(type: 'string')]
     private $name;
 }

The standalone set files stay in place, same as the version sets in #495 — the DoctrineSetList constants remain usable.

Heads-up on scope

This makes annotation-to-attribute conversion part of withComposerBased() rather than an explicit opt-in set. Any project on ORM >= 2.9 and PHP 8 (AnnotationToAttributeRector is still gated on PHP 8.0 by its own min-version) will now get its mapping annotations rewritten to attributes. That is a deliberate migration rather than a version-compat fix, so it is worth a conscious call before merging.

Trigger packages

COMPOSER_BASED_TRIGGER_PACKAGES gains doctrine/mongodb-odm-bundle and gedmo/doctrine-extensions, lowers doctrine/mongodb-odm to >=2.3 and doctrine/data-fixtures to >=1.6, so the set is picked up for projects on those versions.

New tests/ComposerBased fixture covers the ORM annotation-to-attribute path end to end through the composer-based set.

@TomasVotruba
TomasVotruba force-pushed the composer-based-fixtures-attributes branch from 381035c to d28f66a Compare August 3, 2026 15:56
@TomasVotruba
TomasVotruba merged commit 67f49fe into main Aug 3, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the composer-based-fixtures-attributes branch August 3, 2026 16:02
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.

1 participant