Completed
Pull Request — master (#25)
by Dawid
03:13
created

MiddlewareException::forEmptyMiddlewarePipeline()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Igni\Http\Exception;
4
5
use Igni\Exception\RuntimeException;
6
use Psr\Http\Message\RequestInterface;
7
use Psr\Http\Message\ResponseInterface;
8
9
class MiddlewareException extends RuntimeException
10
{
11
    public static function invalidValueReturnedFromMiddleware(): self
12
    {
13
        return new self(sprintf(
14
            'Middleware has returned invalid value, %s expected. Did you forgot return statement?',
15
            ResponseInterface::class
16
        ));
17
    }
18
19
    public static function invalidArgumentsPassedToNextCallback(): self
20
    {
21
        return new self(sprintf(
22
            'Invalid argument(s) passed to `$next` callback, expected %s or/and %s',
23
            RequestInterface::class,
24
            ResponseInterface::class
25
        ));
26
    }
27
28
    public static function forEmptyMiddlewarePipeline(): self
29
    {
30
        return new self('Middleware pipeline is empty.');
31
    }
32
33
    public static function forInvalidMiddlewareResponse($response): self
34
    {
35
        $dumped = var_export($response, true);
36
        return new self(sprintf(
37
            "Middleware failed to produce valid response object, expected instance of `%s` got `%s`".
38
            ResponseInterface::class,
39
            $dumped
40
        ));
41
    }
42
}
43