GiveBackBookFromReservation::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
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