Completed
Push — develop ( fd1e5f...8e6584 )
by Baptiste
02:26
created

DeleteAgendaHandler::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace PersonalGalaxy\Calendar\Handler;
5
6
use PersonalGalaxy\Calendar\{
7
    Command\DeleteAgenda,
8
    Command\CancelEvent,
9
    Repository\AgendaRepository,
10
    Repository\EventRepository,
11
    Entity\Event,
12
    Specification\Agenda,
13
};
14
15
final class DeleteAgendaHandler
16
{
17
    private $agendas;
18
    private $events;
19
    private $cancelEvent;
20
21 1
    public function __construct(
22
        AgendaRepository $agendas,
23
        EventRepository $events,
24
        CancelEventHandler $cancelEvent
25
    ) {
26 1
        $this->agendas = $agendas;
27 1
        $this->events = $events;
28 1
        $this->cancelEvent = $cancelEvent;
29 1
    }
30
31 1
    public function __invoke(DeleteAgenda $wished): void
32
    {
33 1
        $agenda = $this->agendas->get($wished->identity());
34 1
        $agenda->delete();
35
36
        $this
37 1
            ->events
38 1
            ->matching(new Agenda($wished->identity()))
39 1
            ->foreach(function(Event $event): void {
40 1
                ($this->cancelEvent)(new CancelEvent($event->identity()));
41 1
            });
42
43 1
        $this->agendas->remove($agenda->identity());
44 1
    }
45
}
46