Total Complexity | 6 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
17 | class InvalidMiddlewareResolverHandlerException extends InvalidArgumentException |
||
18 | { |
||
19 | /** |
||
20 | * @param mixed $handler |
||
21 | * @return self |
||
22 | */ |
||
23 | 8 | public static function create($handler): self |
|
24 | { |
||
25 | 8 | return new self(sprintf( |
|
26 | 8 | 'Handler "%s" must be an instance or name of a class that implements `%s` or `%s`' |
|
27 | 8 | . ' interface as well as a PHP callable or array of such arguments.', |
|
28 | 8 | self::convertToString($handler), |
|
29 | 8 | MiddlewareInterface::class, |
|
30 | 8 | RequestHandlerInterface::class |
|
31 | 8 | )); |
|
32 | } |
||
33 | |||
34 | /** |
||
35 | * @param mixed $response |
||
36 | * @return self |
||
37 | */ |
||
38 | 6 | public static function forCallableMissingResponse($response): self |
|
39 | { |
||
40 | 6 | return new self(sprintf( |
|
41 | 6 | 'Callable handler must returned an instance of `Psr\Http\Message\ResponseInterface`; received "%s".', |
|
42 | 6 | self::convertToString($response) |
|
43 | 6 | )); |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param string $handler |
||
48 | * @return self |
||
49 | */ |
||
50 | 4 | public static function forStringNotConvertedToInstance(string $handler): self |
|
51 | { |
||
52 | 4 | return new self(sprintf( |
|
53 | 4 | 'String handler "%s" must be a name of a class or an identifier of' |
|
54 | 4 | . ' a container definition that implements `%s` or `%s` interface.', |
|
55 | 4 | $handler, |
|
56 | 4 | MiddlewareInterface::class, |
|
57 | 4 | RequestHandlerInterface::class |
|
58 | 4 | )); |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param mixed $data |
||
63 | * @return string |
||
64 | */ |
||
65 | 14 | private static function convertToString($data): string |
|
68 | } |
||
69 | } |
||
70 |