MoveEventHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 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