[depre] Deprecate GetRepositoryServiceLocatorToRepositoryServiceInjectionRector - #498
Merged
Merged
Conversation
TomasVotruba
force-pushed
the
deprecate-get-repository-service-locator
branch
from
August 3, 2026 15:51
d0fe0cc to
15fed06
Compare
…tionRector The rule resolved the repository class by reading the entity file contents with a regular expression, falling back to the first "use ...Repository;" import. That is too fragile and project specific for a generic rule.
TomasVotruba
force-pushed
the
deprecate-get-repository-service-locator
branch
from
August 3, 2026 15:54
15fed06 to
8c613e8
Compare
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.
This rule turns
$this->getRepository(SomeEntity::class)into a constructor-injected repository:final class SomeClass { + public function __construct( + private SomeEntityRepository $someEntityRepository + ) { + } + public function run() { - return $this->getRepository(SomeEntity::class)->find(1); + return $this->someEntityRepository->find(1); } }To do that, it has to know which repository belongs to the entity.
RepositoryClassResolverdid it by reading the entity file contents and running a regular expression over them:If the
repositoryClass="..."annotation is not matched, it falls back to picking the firstuse ...Repository;import in the file. That silently injects the wrong repository whenever an entity imports any other class ending inRepository, and it misses attribute mapping (#[ORM\Entity(repositoryClass: ...)]) entirely.That is a custom job for a specific project layout, not something a generic rule can do safely. Deprecating it - use a custom rule tailored to your own mapping instead.
The rule was never part of any set, so it only affected users who registered the class by hand.