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