Completed
Push — master ( ca729a...c6cc13 )
by Constantin
02:37
created

CommandDispatcherWithValidator::canExecuteCommand()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
4
namespace Gica\Cqrs\Command\CommandDispatcher;
5
6
7
use Gica\Cqrs\Command;
8
use Gica\Cqrs\Command\CommandDispatcher;
9
use Gica\Cqrs\Command\CommandValidator;
10
use Gica\Cqrs\Command\Exception\CommandValidationFailed;
11
12 View Code Duplication
class CommandDispatcherWithValidator implements CommandDispatcher
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
{
14
15
    /**
16
     * @var CommandDispatcher
17
     */
18
    private $commandDispatcher;
19
    /**
20
     * @var CommandValidator
21
     */
22
    private $commandValidator;
23
24 2
    public function __construct(
25
        CommandDispatcher $commandDispatcher,
26
        CommandValidator $commandValidator
27
28
    )
29
    {
30 2
        $this->commandDispatcher = $commandDispatcher;
31 2
        $this->commandValidator = $commandValidator;
32 2
    }
33
34 2
    public function dispatchCommand(Command $command, $commandMetadata = null)
35
    {
36 2
        $errors = $this->commandValidator->validateCommand($command);
37
38 2
        if (!empty($errors)) {
39 1
            throw new CommandValidationFailed($errors);
40
        }
41
42 1
        $this->commandDispatcher->dispatchCommand($command);
43
    }
44
}