MoveEventHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 23
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 10 2
A __construct() 0 6 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace PersonalGalaxy\Calendar\Handler;
5
6
use PersonalGalaxy\Calendar\{
7
    Command\MoveEvent,
8
    Repository\EventRepository,
9
    Exception\EventCannotBeDeclaredInThePast,
10
};
11
use Innmind\TimeContinuum\TimeContinuumInterface;
12
13
final class MoveEventHandler
14
{
15
    private $repository;
16
    private $clock;
17
18 2
    public function __construct(
19
        EventRepository $repository,
20
        TimeContinuumInterface $clock
21
    ) {
22 2
        $this->repository = $repository;
23 2
        $this->clock = $clock;
24 2
    }
25
26 2
    public function __invoke(MoveEvent $wished): void
27
    {
28 2
        if ($this->clock->now()->aheadOf($wished->slot()->start())) {
29 1
            throw new EventCannotBeDeclaredInThePast($wished->slot());
30
        }
31
32
        $this
33 1
            ->repository
34 1
            ->get($wished->identity())
35 1
            ->move($wished->slot());
36 1
    }
37
}
38