InvalidMiddlewareException::forMiddleware()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace League\Tactician\Exception;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Thrown when the CommandBus was instantiated with an invalid middleware object
9
 */
10
class InvalidMiddlewareException extends InvalidArgumentException implements Exception
11
{
12
    /**
13
     * @param $middleware
14
     *
15
     * @return InvalidMiddlewareException
16
     */
17 1
    public static function forMiddleware($middleware): InvalidMiddlewareException
18
    {
19 1
        $name = is_object($middleware) ? get_class($middleware) : gettype($middleware);
20 1
        $message = sprintf(
21 1
            'Cannot add "%s" to middleware chain as it does not implement the Middleware interface.',
22 1
            $name
23
        );
24 1
        return new static($message);
25
    }
26
}
27