Passed
Branch release/v2.0.0 (caca50)
by Anatoly
03:59
created

BlankRequestHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
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 60
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\RequestHandlerInterface;
11
use Sunrise\Http\Message\ResponseFactory;
12
13
/**
14
 * BlankRequestHandler
15
 */
16
class BlankRequestHandler implements RequestHandlerInterface
17
{
18
19
    /**
20
     * @var bool
21
     */
22
    private $isRunned = false;
23
24
    /**
25
     * @var array
26
     */
27
    private $attributes = [];
28
29
    /**
30
     * @return bool
31
     */
32
    public function isRunned() : bool
33
    {
34
        return $this->isRunned;
35
    }
36
37
    /**
38
     * @return array
39
     */
40
    public function getAttributes() : array
41
    {
42
        return $this->attributes;
43
    }
44
45
    /**
46
     * @param mixed $key
47
     *
48
     * @return mixed
49
     */
50
    public function getAttribute($key)
51
    {
52
        return $this->attributes[$key] ?? null;
53
    }
54
55
    /**
56
     * {@inheritDoc}
57
     */
58
    public function handle(ServerRequestInterface $request) : ResponseInterface
59
    {
60
        $this->isRunned = true;
61
        $this->attributes = $request->getAttributes();
62
63
        return (new ResponseFactory)->createResponse();
64
    }
65
66
    /**
67
     * @param ServerRequestInterface $request
68
     *
69
     * @return ResponseInterface
70
     *
71
     * @link https://www.php.net/manual/ru/language.oop5.magic.php#object.invoke
72
     */
73
    public function __invoke(ServerRequestInterface $request) : ResponseInterface
74
    {
75
        return $this->handle($request);
76
    }
77
}
78