Skip to content

[TypeDeclaration] Add ReturnTypeFromGetRepositoryDocblockRector#8146

Merged
TomasVotruba merged 2 commits into
mainfrom
return-type-from-get-repository-docblock
Jul 5, 2026
Merged

[TypeDeclaration] Add ReturnTypeFromGetRepositoryDocblockRector#8146
TomasVotruba merged 2 commits into
mainfrom
return-type-from-get-repository-docblock

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Adds ReturnTypeFromGetRepositoryDocblockRector.

Moves a @return docblock type into a native return type when a method's sole return is an EntityManagerInterface::getRepository() fetch.

 final class EventModel
 {
     public function __construct(private \Doctrine\ORM\EntityManagerInterface $em)
     {
     }

-    /**
-     * @return \Mautic\CampaignBundle\Entity\EventRepository
-     */
-    public function getRepository()
+    public function getRepository(): \Mautic\CampaignBundle\Entity\EventRepository
     {
         return $this->em->getRepository(Event::class);
     }
 }

Guards

  • skips if a native return type is already present
  • exactly one scoped return, whose expr is a getRepository() method call
  • caller must be (or implement) Doctrine\ORM\EntityManagerInterface
  • @return must resolve to a plain, existing class (ReflectionProvider::hasClass); generic / non-existing types are skipped
  • ClassMethodReturnTypeOverrideGuard prevents breaking parent/child signatures
  • the now-redundant @return tag is removed

Move @return docblock type into native return type on methods that return an EntityManagerInterface getRepository() fetch.
@TomasVotruba TomasVotruba enabled auto-merge (squash) July 5, 2026 08:54
@TomasVotruba TomasVotruba disabled auto-merge July 5, 2026 08:54
@TomasVotruba TomasVotruba merged commit 9ca6fae into main Jul 5, 2026
65 checks passed
@TomasVotruba TomasVotruba deleted the return-type-from-get-repository-docblock branch July 5, 2026 09:24
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