Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 20
n/a
0 / 0
n/a
0 / 0
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
DoctrineSetRepository
0.00% covered (danger)
0.00%
0 / 19
n/a
0 / 0
n/a
0 / 0
0.00% covered (danger)
0.00%
0 / 4
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
n/a
0 / 0
n/a
0 / 0
0.00% covered (danger)
0.00%
0 / 1
2
 add
0.00% covered (danger)
0.00%
0 / 2
n/a
0 / 0
n/a
0 / 0
0.00% covered (danger)
0.00%
0 / 1
2
 update
0.00% covered (danger)
0.00%
0 / 2
n/a
0 / 0
n/a
0 / 0
0.00% covered (danger)
0.00%
0 / 1
2
 findByUserAndExternalIds
0.00% covered (danger)
0.00%
0 / 14
n/a
0 / 0
n/a
0 / 0
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\CollectionManagement\Infrastructure\Persistence\Doctrine\Repository;
4
5use App\CollectionManagement\Domain\Model\Local\Set;
6use App\CollectionManagement\Domain\Model\SetCollection;
7use App\CollectionManagement\Domain\Port\Driven\LocalSetRepository;
8use App\CollectionManagement\Infrastructure\Persistence\Doctrine\Entity\DoctrineSet;
9use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
10use Doctrine\ORM\EntityManagerInterface;
11use Doctrine\Persistence\ManagerRegistry;
12use Override;
13use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
14
15/**
16 * @author Wilhelm Zwertvaegher
17 * @extends ServiceEntityRepository<DoctrineSet>
18 *
19 */
20#[Autoconfigure]
21class 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}