Completed
Pull Request — master (#5)
by Nicolas
10:36 queued 09:37
created

CommandHandlerNotFound::forCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 6
cts 6
cp 1
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php declare(strict_types=1);
2
3
namespace BSP\CommandBus\Exception;
4
5
use Throwable;
6
7
final class CommandHandlerNotFound extends \RuntimeException
8
{
9 1
    private function __construct(
10
        $message,
11
        $code = 0,
12
        Throwable $previous = null
13
    ) {
14 1
        parent::__construct($message, $code, $previous);
15 1
    }
16
17 1
    public static function forCommand(string $commandClass, int $code = 0, Throwable $previous = null): self
18
    {
19 1
        $message = sprintf(
20 1
            "I cannot find a handler for the command `%s`. You should check those possibilities: %s
21
            - You forgot to inject a CommandHandlerMap to the CommandBus. %s
22
            - You forgot to add the couple command/handler to your CommandHandlerMap.",
23
            $commandClass,
24 1
            PHP_EOL,
25 1
            PHP_EOL
26
        );
27
28 1
        return new self($message, $code, $previous);
29
    }
30
}
31