CommandValidatorSubscriberByMap   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getHandlersForCommand() 0 21 3
getCommandHandlersDefinitions() 0 1 ?
1
<?php
2
/******************************************************************************
3
 * Copyright (c) 2016 Constantin Galbenu <[email protected]>             *
4
 ******************************************************************************/
5
6
namespace Gica\Cqrs\Command\CommandValidation;
7
8
9
use Gica\Cqrs\Command;
10
use Gica\Cqrs\Command\CommandValidation;
11
use Gica\Cqrs\Command\ValueObject\CommandHandlerDescriptor;
12
13
abstract class CommandValidatorSubscriberByMap implements CommandValidation\CommandValidatorSubscriber
14
{
15
    /**
16
     * @inheritdoc
17
     */
18 2
    public function getHandlersForCommand(Command $command)
19
    {
20 2
        $definitions = $this->getCommandHandlersDefinitions();
21
22 2
        if (!isset($definitions[get_class($command)])) {
23 1
            return [];
24
        }
25
26 1
        $handlersForCommand = $definitions[get_class($command)];
27
28 1
        $result = [];
29
30 1
        foreach ($handlersForCommand as $commandDefinition) {
31
32 1
            list($aggregateClass, $methodName) = $commandDefinition;
33
34 1
            $result[] = new CommandHandlerDescriptor($aggregateClass, $methodName);
35
        }
36
37 1
        return $result;
38
    }
39
40
    abstract protected function getCommandHandlersDefinitions(): array;
41
}