LocalListReservationsForBookProjection::get()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 19
rs 9.2
cc 4
eloc 10
nc 3
nop 1
1
<?php
2
3
namespace Clearcode\EHLibrary\Infrastructure\Projection;
4
5
use Clearcode\EHLibrary\Application\Projection\ListReservationsForBookProjection;
6
use Clearcode\EHLibrary\Application\Projection\ReservationView;
7
use Clearcode\EHLibrary\Infrastructure\Persistence\LocalReservationRepository;
8
use Clearcode\EHLibrary\Model\Reservation;
9
use Clearcode\EHLibrary\Model\ReservationRepository;
10
use Ramsey\Uuid\UuidInterface;
11
12
class LocalListReservationsForBookProjection implements ListReservationsForBookProjection
13
{
14
    /** @var ReservationRepository */
15
    private $repository;
16
17
    public function __construct()
18
    {
19
        $this->repository = new LocalReservationRepository();
20
    }
21
22
    /** {@inheritdoc} */
23
    public function get(UuidInterface $bookId)
24
    {
25
        $views = [];
26
27
        /** @var Reservation $reservation */
28
        foreach ($this->repository->getAll() as $reservation) {
29
            if (!$reservation->bookId()->equals($bookId)) {
30
                continue;
31
            }
32
33
            $views[] = new ReservationView(
34
                (string) $reservation->id(),
35
                $reservation->email(),
36
                ($reservation->isGivenAway()) ? $reservation->givenAwayAt()->format('Y-m-d H:i:s') : null
37
            );
38
        }
39
40
        return $views;
41
    }
42
}
43