GiveBackBookFromReservation::giveBack()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 10
rs 9.4286
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace Clearcode\EHLibrary\Application\UseCase;
4
5
use Clearcode\EHLibrary\Model\CannotGiveBackReservationWhichWasNotGivenAway;
6
use Clearcode\EHLibrary\Model\ReservationRepository;
7
use Ramsey\Uuid\UuidInterface;
8
9
class GiveBackBookFromReservation
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
     *
25
     * @throws CannotGiveBackReservationWhichWasNotGivenAway
26
     */
27
    public function giveBack(UuidInterface $reservationId)
28
    {
29
        $reservation = $this->reservations->get($reservationId);
30
31
        if (!$reservation->isGivenAway()) {
32
            throw new CannotGiveBackReservationWhichWasNotGivenAway(sprintf('Cannot give back reservation %s which was not given away.', $reservation->id()));
33
        }
34
35
        $this->reservations->remove($reservationId);
36
    }
37
}
38