Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
DoctrineTripRepository
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
5 / 5
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 save
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 remove
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 ofId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 ofOwner
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Trip\Infrastructure\Persistence\Doctrine;
6
7use App\Trip\Domain\Trip;
8use App\Trip\Domain\TripRepository;
9use App\Trip\Domain\ValueObject\OwnerId;
10use App\Trip\Domain\ValueObject\TripId;
11use Doctrine\ORM\EntityManagerInterface;
12
13final class DoctrineTripRepository implements TripRepository
14{
15    public function __construct(private readonly EntityManagerInterface $entityManager)
16    {
17    }
18
19    public function save(Trip $trip): void
20    {
21        $this->entityManager->persist($trip);
22        $this->entityManager->flush();
23    }
24
25    public function remove(Trip $trip): void
26    {
27        $this->entityManager->remove($trip);
28        $this->entityManager->flush();
29    }
30
31    public function ofId(TripId $id): ?Trip
32    {
33        return $this->entityManager->find(Trip::class, $id);
34    }
35
36    public function ofOwner(OwnerId $ownerId): array
37    {
38        return $this->entityManager->getRepository(Trip::class)
39            ->findBy(['ownerId' => $ownerId], ['createdAt' => 'DESC']);
40    }
41}