[composer-based] Bond data-fixtures rule and annotation-to-attribute sets to composer package constraints - #497
Merged
Conversation
…sets to composer package constraints
TomasVotruba
force-pushed
the
composer-based-fixtures-attributes
branch
from
August 3, 2026 15:56
381035c to
d28f66a
Compare
…, drop the dev dependency
TomasVotruba
added a commit
to TomasVotruba/drupal-rector
that referenced
this pull request
Aug 10, 2026
The generator rewrote the per-minor configs by walking their PHP tokens and patching the registration calls, which made the set a build artifact of a parser rather than a config you can read. Keeps the set as a plain config of real rules, in the shape rector-doctrine uses (rectorphp/rector-doctrine#497), and accepts that a rule is registered both here and in its per-minor config. `ComposerBasedSetTest` fails when a rule of a per-minor config is missing here, so the duplication cannot drift unnoticed.
TomasVotruba
added a commit
to TomasVotruba/drupal-rector
that referenced
this pull request
Aug 10, 2026
…e shape Follows rectorphp/rector-doctrine#497: a rule that takes no configuration declares the version its target API landed in on the rule class, instead of being gated by the set that registers it. -$ruleSince(LoadAllIncludesRector::class, '>=11.3.0'); +$rectorConfig->rule(LoadAllIncludesRector::class); +final class LoadAllIncludesRector extends AbstractRector implements ComposerPackageConstraintInterface, DocumentedRuleInterface +{ + public function provideComposerPackageConstraint(): ComposerPackageConstraint + { + return new ComposerPackageConstraint('drupal/core', '>=11.3.0'); + } 76 rules are bonded this way, which drops the `$ruleSince()` helper and the `Semver` lookup from the set. The three rector-phpunit rules the Drupal 10.1 config registers are dropped from the set as well: they are already bonded to `phpunit/phpunit` by rector-phpunit's own composer-based set, which is the accurate constraint for them. Rector applies the constraint filter globally rather than per set, so these rules no longer run against a core older than the deprecation, including when a `Drupal*SetList` set is loaded by hand. Verified against a project on 11.2.3 and one on 11.3.0: `LoadAllIncludesRector` fires only on the latter. Rule tests point `provideComposerJsonFilePath()` at a stub composer.json that requires drupal/core, as this package does not — without it every bonded rule would be filtered out of its own test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #495. Two gaps remained after the composer-based bonding.
1.
AddGetReferenceTypeRectorhad no composer constraintThe 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 registersdata-fixtures-16.phpas aComposerTriggeredSetat1.6— but the rule itself carried noComposerPackageConstraintInterface, and unlike itsdata-fixtures-17sibling it was never added tocomposer-based.php.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-fixturesis added torequire-devso 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_ATTRIBUTESandMONGODB_ANNOTATIONS_TO_ATTRIBUTESconvert annotations to attribute classes that only exist from a specific package version. Each config block moves intocomposer-based.phpbound to the version that first shipped those classes as PHP 8 attributes:doctrine/orm>=2.9#[Attribute]onMapping\Entityabsent in 2.8.0, present in 2.9.0doctrine/mongodb-odm>=2.3doctrine/mongodb-odm-bundle>=4.4Validator\Constraints\Uniqueabsent in 4.3.0, present in 4.4.0gedmo/doctrine-extensions>=3.5Mapping\Annotation\Slugabsent in v3.4.0, present in v3.5.0The
Uniqueconstraint 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():The standalone set files stay in place, same as the version sets in #495 — the
DoctrineSetListconstants 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 (AnnotationToAttributeRectoris 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_PACKAGESgainsdoctrine/mongodb-odm-bundleandgedmo/doctrine-extensions, lowersdoctrine/mongodb-odmto>=2.3anddoctrine/data-fixturesto>=1.6, so the set is picked up for projects on those versions.New
tests/ComposerBasedfixture covers the ORM annotation-to-attribute path end to end through the composer-based set.