Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
0.00% |
0 / 20 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
||
| DoctrineSetRepository | |
0.00% |
0 / 19 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 4 |
20 | |
0.00% |
0 / 1 |
||
| __construct | |
0.00% |
0 / 1 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 1 |
2 | |||||
| add | |
0.00% |
0 / 2 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 1 |
2 | |||||
| update | |
0.00% |
0 / 2 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 1 |
2 | |||||
| findByUserAndExternalIds | |
0.00% |
0 / 14 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 1 |
2 | |||||
| 1 | <?php |
| 2 | |
| 3 | namespace App\CollectionManagement\Infrastructure\Persistence\Doctrine\Repository; |
| 4 | |
| 5 | use App\CollectionManagement\Domain\Model\Local\Set; |
| 6 | use App\CollectionManagement\Domain\Model\SetCollection; |
| 7 | use App\CollectionManagement\Domain\Port\Driven\LocalSetRepository; |
| 8 | use App\CollectionManagement\Infrastructure\Persistence\Doctrine\Entity\DoctrineSet; |
| 9 | use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
| 10 | use Doctrine\ORM\EntityManagerInterface; |
| 11 | use Doctrine\Persistence\ManagerRegistry; |
| 12 | use Override; |
| 13 | use Symfony\Component\DependencyInjection\Attribute\Autoconfigure; |
| 14 | |
| 15 | /** |
| 16 | * @author Wilhelm Zwertvaegher |
| 17 | * @extends ServiceEntityRepository<DoctrineSet> |
| 18 | * |
| 19 | */ |
| 20 | #[Autoconfigure] |
| 21 | class DoctrineSetRepository extends ServiceEntityRepository implements LocalSetRepository |
| 22 | { |
| 23 | public function __construct(ManagerRegistry $managerRegistry, private readonly EntityManagerInterface $entityManager) |
| 24 | { |
| 25 | parent::__construct($managerRegistry, DoctrineSet::class); |
| 26 | } |
| 27 | |
| 28 | #[Override] |
| 29 | public function add(Set $localSet): void |
| 30 | { |
| 31 | $this->entityManager->persist($localSet); |
| 32 | } |
| 33 | |
| 34 | #[Override] |
| 35 | public function update(Set $localSet): void |
| 36 | { |
| 37 | // Nothing to do as we use Doctrine, and all changes to the entity are implicitly handled by doctrine |
| 38 | // as long as the Set is handled by doctrine itself which MUST be the case here |
| 39 | } |
| 40 | |
| 41 | #[Override] |
| 42 | public function findByUserAndExternalIds(string $userId, array $externalIds): SetCollection |
| 43 | { |
| 44 | return new SetCollection( |
| 45 | array_map( |
| 46 | fn (DoctrineSet $s) => $s->toDomain(), |
| 47 | $this->createQueryBuilder('s') |
| 48 | ->join('s.userSets', 'us') |
| 49 | ->where('us.user = :userId') |
| 50 | ->andWhere('s.externalId IN (:externalIds)') |
| 51 | ->setParameter('userId', $userId) |
| 52 | ->setParameter('externalIds', $externalIds) |
| 53 | ->getQuery() |
| 54 | ->getResult() |
| 55 | ) |
| 56 | ); |
| 57 | } |
| 58 | } |