Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| DoctrineTripMemberRepository | |
100.00% |
14 / 14 |
|
100.00% |
7 / 7 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| save | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| remove | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| roleOf | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| find | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| ofTrip | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| ofUser | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Trip\Infrastructure\Persistence\Doctrine; |
| 6 | |
| 7 | use App\Trip\Domain\TripMember; |
| 8 | use App\Trip\Domain\TripMemberRepository; |
| 9 | use App\Trip\Domain\ValueObject\MemberId; |
| 10 | use App\Trip\Domain\ValueObject\TripId; |
| 11 | use App\Trip\Domain\ValueObject\TripRole; |
| 12 | use Doctrine\ORM\EntityManagerInterface; |
| 13 | |
| 14 | final class DoctrineTripMemberRepository implements TripMemberRepository |
| 15 | { |
| 16 | public function __construct(private readonly EntityManagerInterface $entityManager) |
| 17 | { |
| 18 | } |
| 19 | |
| 20 | public function save(TripMember $member): void |
| 21 | { |
| 22 | $this->entityManager->persist($member); |
| 23 | $this->entityManager->flush(); |
| 24 | } |
| 25 | |
| 26 | public function remove(TripMember $member): void |
| 27 | { |
| 28 | $this->entityManager->remove($member); |
| 29 | $this->entityManager->flush(); |
| 30 | } |
| 31 | |
| 32 | public function roleOf(TripId $tripId, MemberId $userId): ?TripRole |
| 33 | { |
| 34 | $member = $this->entityManager->getRepository(TripMember::class) |
| 35 | ->findOneBy(['tripId' => $tripId, 'userId' => $userId]); |
| 36 | |
| 37 | return $member?->role(); |
| 38 | } |
| 39 | |
| 40 | public function find(TripId $tripId, MemberId $userId): ?TripMember |
| 41 | { |
| 42 | return $this->entityManager->getRepository(TripMember::class) |
| 43 | ->findOneBy(['tripId' => $tripId, 'userId' => $userId]); |
| 44 | } |
| 45 | |
| 46 | public function ofTrip(TripId $tripId): array |
| 47 | { |
| 48 | return $this->entityManager->getRepository(TripMember::class) |
| 49 | ->findBy(['tripId' => $tripId], ['createdAt' => 'ASC']); |
| 50 | } |
| 51 | |
| 52 | public function ofUser(MemberId $userId): array |
| 53 | { |
| 54 | return $this->entityManager->getRepository(TripMember::class) |
| 55 | ->findBy(['userId' => $userId], ['createdAt' => 'DESC']); |
| 56 | } |
| 57 | } |