InvalidCommandHandler::triedToAssign()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 12
rs 9.9666
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