Passed
Pull Request — master (#54)
by Frank
02:24
created

DummyCommandHandler::handle()   A

Complexity

Conditions 5
Paths 9

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 12
c 1
b 0
f 0
nc 9
nop 1
dl 0
loc 17
ccs 12
cts 12
cp 1
crap 5
rs 9.5555
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EventSauce\EventSourcing\Integration\TestingAggregates;
6
7
use EventSauce\EventSourcing\AggregateRootRepository;
8
use EventSauce\EventSourcing\Time\Clock;
9
10
class DummyCommandHandler
11
{
12
    /**
13
     * @var AggregateRootRepository
14
     */
15
    private $repository;
16
17
    /**
18
     * @var Clock
19
     */
20
    private $clock;
21
22 8
    public function __construct(AggregateRootRepository $repository, Clock $clock)
23
    {
24 8
        $this->repository = $repository;
25 8
        $this->clock = $clock;
26 8
    }
27
28
    /**
29
     * @param DummyCommand $command
30
     *
31
     * @throws DummyException
32
     */
33 8
    public function handle($command)
34
    {
35
        /** @var DummyAggregate $aggregate */
36 8
        $aggregate = $this->repository->retrieve($command->aggregateRootId());
37
38
        try {
39 8
            if ($command instanceof DummyCommand) {
0 ignored issues
show
introduced by
$command is always a sub-type of EventSauce\EventSourcing...Aggregates\DummyCommand.
Loading history...
40 1
                $aggregate->performDummyTask();
41 7
            } elseif ($command instanceof IgnoredCommand) {
42 1
                $aggregate->dontDoAnything();
43 6
            } elseif ($command instanceof ExceptionInducingCommand) {
44 3
                $aggregate->throwAnException();
45 3
            } elseif ($command instanceof DummyIncrementCommand) {
46 3
                $aggregate->increment();
47
            }
48 5
        } finally {
49 8
            $this->repository->persist($aggregate);
50
        }
51 5
    }
52
}
53