Files
ai-chat/.continue/rules/simplify-repository-usage.md
2026-06-10 18:22:27 +02:00

1.2 KiB

globs, description, alwaysApply
globs description alwaysApply
["src/**/*Repository.php"] Ensures minimal boilerplate by avoiding unnecessary custom Repository classes for standard CRUD operations, while still allowing them for complex queries. true

In Symfony and Doctrine based applications, avoid creating custom Repository classes for simple CRUD or standard query operations (e.g., findOneBy, findBy). Instead, use Doctrine's native EntityRepository directly via $entityManager->getRepository(Entity::class) within the Provider or Processor implementations.

Only create a custom repository when:

  1. Complex queries involving multiple joins, subselects, or specialized search logic are required.
  2. Query logic is reused across multiple Providers/Processors and warrants encapsulation for DRY compliance.

When no custom repository is needed, Inject EntityManagerInterface directly into the Provider or Processor and fetch the repository inline as shown below:

$repository = $this->entityManager->getRepository(EntityClass::class);
$result = $repository->findOneBy(['id' => $id]);

Do not create an empty or wrapper Repository class that only delegates to Doctrine's native methods.