Completed
Pull Request — master (#5)
by Nicolas
10:11
created

CommandHandlerNotFound   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 24
c 0
b 0
f 0
wmc 2
lcom 0
cbo 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A forCommand() 0 13 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
    private function __construct(
10
        $message,
11
        $code = 0,
12
        Throwable $previous = null
13
    ) {
14
        parent::__construct($message, $code, $previous);
15
    }
16
17
    public static function forCommand(string $commandClass, int $code = 0, Throwable $previous = null): self
18
    {
19
        $message = sprintf(
20
            "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
            PHP_EOL,
25
            PHP_EOL
26
        );
27
28
        return new self($message, $code, $previous);
29
    }
30
}
31