GiveAwayBookInReservation   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 3
c 5
b 0
f 1
lcom 1
cbo 3
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A giveAway() 0 12 2
1
<?php
2
3
namespace Clearcode\EHLibrary\Application\UseCase;
4
5
use Clearcode\EHLibrary\Model\BookInReservationAlreadyGivenAway;
6
use Clearcode\EHLibrary\Model\ReservationRepository;
7
use Ramsey\Uuid\UuidInterface;
8
9
class GiveAwayBookInReservation
10
{
11
    /** @var ReservationRepository */
12
    private $reservations;
13
14
    /**
15
     * @param ReservationRepository $reservations
16
     */
17
    public function __construct(ReservationRepository $reservations)
18
    {
19
        $this->reservations = $reservations;
20
    }
21
22
    /**
23
     * @param UuidInterface $reservationId
24
     * @param \DateTime     $givenAwayAt
25
     *
26
     * @throws BookInReservationAlreadyGivenAway
27
     */
28
    public function giveAway(UuidInterface $reservationId, \DateTime $givenAwayAt)
29
    {
30
        $reservation = $this->reservations->get($reservationId);
31
32
        if ($this->reservations->existsAlreadyGivenOfBook($reservation->bookId())) {
33
            throw new BookInReservationAlreadyGivenAway(sprintf('Book with id %s in reservation with id %s was already given away.', $reservation->bookId(), $reservation->id()));
34
        }
35
36
        $reservation->giveAway($givenAwayAt);
37
38
        $this->reservations->save($reservation);
39
    }
40
}
41