DeleteAgendaHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 29
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 13 1
A __construct() 0 8 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