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

DummyCommandHandler   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 40
ccs 16
cts 16
cp 1
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 17 5
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