Skip to content

[doctrine] Add NoGetRepositoryOnServiceRepositoryEntityRule#182

Merged
TomasVotruba merged 1 commit intomainfrom
tv-doctrine-no-get-repository-on-service-entity
Feb 25, 2025
Merged

[doctrine] Add NoGetRepositoryOnServiceRepositoryEntityRule#182
TomasVotruba merged 1 commit intomainfrom
tv-doctrine-no-get-repository-on-service-entity

Conversation

@TomasVotruba
Copy link
Copy Markdown
Member

@TomasVotruba TomasVotruba commented Feb 25, 2025

Instead of calling "->getRepository(...::class)" service locator, inject service repository via constructor and use it directly

rules:
    - Symplify\PHPStanRules\Rules\Doctrine\NoGetRepositoryOnServiceRepositoryEntityRule

use Doctrine\ORM\Mapping as ORM;
/**
 * @ORM\Entity(repositoryClass=SomeRepository::class)
 */
class SomeEntity
{
}

use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
final class SomeEntityRepository extends ServiceEntityRepository
{
}

use Doctrine\ORM\EntityManagerInterface;
final class SomeService
{
    public function run(EntityManagerInterface $entityManager)
    {
        return $this->entityManager->getRepository(SomeEntity::class);
    }
}


use Doctrine\ORM\EntityManagerInterface;
final class SomeService
{
    public function __construct(private SomeEntityRepository $someEntityRepository)
    {
    }
}

👍

@TomasVotruba TomasVotruba merged commit dd825e8 into main Feb 25, 2025
6 checks passed
@TomasVotruba TomasVotruba deleted the tv-doctrine-no-get-repository-on-service-entity branch February 25, 2025 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant