GiveBackBookFromReservation   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A giveBack() 0 10 2
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