Passed
Pull Request — master (#54)
by Frank
01:53
created

DummyCommandHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
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
    public function __construct(AggregateRootRepository $repository, Clock $clock)
23
    {
24
        $this->repository = $repository;
25
        $this->clock = $clock;
26
    }
27
28
    /**
29
     * @param DummyCommand $command
30
     *
31
     * @throws DummyException
32
     */
33
    public function handle($command)
34
    {
35
        /** @var DummyAggregate $aggregate */
36
        $aggregate = $this->repository->retrieve($command->aggregateRootId());
37
38
        try {
39
            if ($command instanceof DummyCommand) {
0 ignored issues
show
introduced by
$command is always a sub-type of EventSauce\EventSourcing...Aggregates\DummyCommand.
Loading history...
40
                $aggregate->performDummyTask();
41
            } elseif ($command instanceof IgnoredCommand) {
42
                $aggregate->dontDoAnything();
43
            } elseif ($command instanceof ExceptionInducingCommand) {
44
                $aggregate->throwAnException();
45
            } elseif ($command instanceof DummyIncrementCommand) {
46
                $aggregate->increment();
47
            }
48
        } finally {
49
            $this->repository->persist($aggregate);
50
        }
51
    }
52
}
53