Completed
Push — master ( c6cc13...35df44 )
by Constantin
02:33
created

__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 4
cts 4
cp 1
rs 9.6666
cc 1
eloc 5
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * Copyright (c) 2017 Constantin Galbenu <[email protected]>
4
 */
5
6
namespace Gica\Cqrs\Command\CommandTester;
7
8
9
use Gica\Cqrs\Command;
10
use Gica\Cqrs\Command\CommandTesterWithExplanation;
11
use Gica\Cqrs\Command\CommandValidator;
12
13
class CommandTesterWithExplanationWithValidator implements CommandTesterWithExplanation
14
{
15
16
    /**
17
     * @var CommandTesterWithExplanation
18
     */
19
    private $commandTester;
20
    /**
21
     * @var CommandValidator
22
     */
23
    private $commandValidator;
24
25 1
    public function __construct(
26
        CommandTesterWithExplanation $commandTester,
27
        CommandValidator $commandValidator
28
29
    )
30
    {
31 1
        $this->commandTester = $commandTester;
32 1
        $this->commandValidator = $commandValidator;
33 1
    }
34
35 1
    public function whyCantExecuteCommand(Command $command)
36
    {
37 1
        $unknownErrors = $this->commandValidator->validateCommand($command);
38
39 1
        $validatorErrors = array_map(function ($error) {
40 1
            if (!($error instanceof \Throwable)) {
41 1
                $error = new \Exception((string)$error);
42
            }
43
44 1
            return $error;
45 1
        }, $unknownErrors);
46
47
        $testerErrors = $this->commandTester->whyCantExecuteCommand($command);
48
49
        return array_merge($validatorErrors, $testerErrors);
50
    }
51
}