Completed
Push — master ( 4803b3...959101 )
by Frank
03:46
created

DummyCommandHandler   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 38
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B handle() 0 19 5
1
<?php
2
3
namespace EventSauce\EventSourcing\Integration\TestingAggregates;
4
5
use EventSauce\EventSourcing\AggregateRootRepository;
6
use EventSauce\EventSourcing\Command;
7
use EventSauce\EventSourcing\CommandHandler;
8
use EventSauce\EventSourcing\Time\Clock;
9
10
class DummyCommandHandler implements CommandHandler
11
{
12
    /**
13
     * @var AggregateRootRepository
14
     */
15
    private $repository;
16
17
    /**
18
     * @var Clock
19
     */
20
    private $clock;
21
22 6
    public function __construct(AggregateRootRepository $repository, Clock $clock)
23
    {
24 6
        $this->repository = $repository;
25 6
        $this->clock = $clock;
26 6
    }
27
28 6
    public function handle(Command $command)
29
    {
30
        /** @var DummyAggregate $aggregate */
31 6
        $aggregate = $this->repository->retrieve($command->aggregateRootId());
32
33
        try {
34 6
            if ($command instanceof DummyCommand) {
35 1
                $aggregate->performDummyTask($this->clock);
36 5
            } elseif ($command instanceof IgnoredCommand) {
37 1
                $aggregate->dontDoAnything();
38 4
            } elseif ($command instanceof ExceptionInducingCommand) {
39 3
                $aggregate->throwAnException();
40 1
            } elseif ($command instanceof DummyIncrementCommand) {
41 1
                $aggregate->increment($this->clock);
42
            }
43 3
        } finally {
44 6
            $this->repository->persist($aggregate);
45
        }
46
    }
47
}