CommandHandlersMapCodeGenerator::log()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/******************************************************************************
3
 * Copyright (c) 2017 Constantin Galbenu <[email protected]>             *
4
 ******************************************************************************/
5
6
namespace Gica\Cqrs\CodeGeneration;
7
8
use Gica\CodeAnalysis\MethodListenerDiscovery;
9
use Gica\CodeAnalysis\MethodListenerDiscovery\ListenerClassValidator\AnyPhpClassIsAccepted;
10
use Gica\CodeAnalysis\MethodListenerDiscovery\MapGrouper\GrouperByEvent;
11
use Gica\Cqrs\CodeGeneration\Traits\GroupedByEventTrait;
12
use Gica\Cqrs\Command\CodeAnalysis\AggregateCommandHandlerDetector;
13
14
class CommandHandlersMapCodeGenerator
15
{
16
    use GroupedByEventTrait;
17
18 1
    protected function log($outputFilePath)
19
    {
20 1
        $this->logger->info("Commands map wrote to: $outputFilePath");
21 1
    }
22
23 2
    private function validateMap(array $map)
24
    {
25 2
        foreach ($map as $command => $commandHandlers) {
26 2
            if (count($commandHandlers) > 1) {
27 1
                throw new \Exception(
28 2
                    sprintf("multiple handlers exists for command %s", $command));
29
            }
30
        }
31 1
    }
32
33 2
    protected function discover(\Iterator $files)
34
    {
35 2
        $discoverer = new MethodListenerDiscovery(
36 2
            new AggregateCommandHandlerDetector(),
37 2
            new AnyPhpClassIsAccepted);
38
39 2
        $map = $discoverer->discoverListeners($files);
40
41 2
        $this->validateMap($this->groupMap($map));
42
43 1
        return $map;
44
    }
45
46 2
    private function groupMap(array $map)
47
    {
48 2
        return (new GrouperByEvent())->groupMap($map);
49
    }
50
}