Skip to content

[DI] Use entropy autodiscover() over registerTagged() for order-independent service collections - #8370

Merged
TomasVotruba merged 2 commits into
mainfrom
autodiscover-tagged-services
Aug 25, 2026
Merged

[DI] Use entropy autodiscover() over registerTagged() for order-independent service collections#8370
TomasVotruba merged 2 commits into
mainfrom
autodiscover-tagged-services

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Replaces four registerTagged() calls in LazyContainerFactory with entropy's autodiscover(), which scans a directory and registers everything found. Shorter, and it drops four hand-maintained class-string constants plus their imports.

Only the collections whose consumers are order-independent were converted, because findByContract() returns services in registration order and autodiscover() uses filesystem (readdir) order, not the curated constant order:

CollectionConsumer patternConverted
NodeTypeResolverInterfacekeyed by node classyes
OutputFormatterInterfacekeyed by getName()yes
ClassNameImportSkipVoterInterfacearray_any (any voter)yes
ConverterAttributeDecoratorInterfaceexact name matchyes

First-match collections (TypeMapperInterface, PhpDocTypeMapperInterface, PhpParserNodeMapperInterface, NodeNameResolverInterface, AnnotationToAttributeMapperInterface) keep registerTagged() — their curated order is significant and must not depend on the filesystem.

- $this->registerTagged($rectorConfig, self::NODE_TYPE_RESOLVER_CLASSES, NodeTypeResolverInterface::class);- $this->registerTagged($rectorConfig, self::OUTPUT_FORMATTER_CLASSES, OutputFormatterInterface::class);- $this->registerTagged(- $rectorConfig,- self::CLASS_NAME_IMPORT_SKIPPER_CLASSES,- ClassNameImportSkipVoterInterface::class- );+ $rectorConfig->autodiscover(__DIR__ . '/../NodeTypeResolver/NodeTypeResolver');+ $rectorConfig->autodiscover(__DIR__ . '/../ChangesReporting/Output');+ $rectorConfig->autodiscover(__DIR__ . '/../../rules/CodingStyle/ClassNameImport/ClassNameImportSkipVoter');

Verified each converted contract still resolves the exact same service count after boot (4 / 12 / 7 / 2).

@TomasVotruba
TomasVotruba enabled auto-merge (squash) August 25, 2026 06:57
@TomasVotruba
TomasVotruba merged commit d6aa6e3 into mainAug 25, 2026
43 of 44 checks passed
@TomasVotruba
TomasVotruba deleted the autodiscover-tagged-services branch August 25, 2026 06:58
Sign up for freeto 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

@TomasVotruba