InvalidCommandHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 16
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A triedToAssign() 0 12 2
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CommandHandling;
4
5
use function get_class;
6
use function gettype;
7
use InvalidArgumentException as InvalidArgument;
8
use function is_object;
9
use function sprintf;
10
11
/**
12
 * Exception to throw when trying to configure a command handler that does not
13
 * implement the expected interface.
14
 */
15
final class InvalidCommandHandler
16
    extends InvalidArgument
17
    implements InvalidBusConfiguration
18
{
19
    public static function triedToAssign($handler): InvalidBusConfiguration
20
    {
21
        return new self(
22
            is_object($handler)
23
            ? sprintf(
24
                'The requested command handler `%s` does not implement `%s`.',
25
                get_class($handler),
26
                Handler::class
27
            )
28
            : sprintf(
29
                'Cannot assign a primitive %s as command handler.',
30
                gettype($handler)
31
            )
32
        );
33
    }
34
}
35