Passed
Branch release/v2.0.0 (caca50)
by Anatoly
02:10
created

BlankMiddleware   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
c 1
b 0
f 0
dl 0
loc 49
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Sunrise\Http\Router\Tests\Fixture;
4
5
/**
6
 * Import classes
7
 */
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Psr\Http\Server\MiddlewareInterface;
11
use Psr\Http\Server\RequestHandlerInterface;
12
use Sunrise\Http\Message\ResponseFactory;
13
14
/**
15
 * BlankMiddleware
16
 */
17
class BlankMiddleware implements MiddlewareInterface
18
{
19
20
    /**
21
     * @var bool
22
     */
23
    private $isBroken;
24
25
    /**
26
     * @var bool
27
     */
28
    private $isRunned = false;
29
30
    /**
31
     * @param bool $isBroken
32
     */
33
    public function __construct(bool $isBroken = false)
34
    {
35
        $this->isBroken = $isBroken;
36
    }
37
38
    /**
39
     * @return bool
40
     */
41
    public function isBroken() : bool
42
    {
43
        return $this->isBroken;
44
    }
45
46
    /**
47
     * @return bool
48
     */
49
    public function isRunned() : bool
50
    {
51
        return $this->isRunned;
52
    }
53
54
    /**
55
     * {@inheritDoc}
56
     */
57
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
58
    {
59
        $this->isRunned = true;
60
61
        if ($this->isBroken) {
62
            return (new ResponseFactory)->createResponse();
63
        }
64
65
        return $handler->handle($request);
66
    }
67
}
68