Route::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace PTS\Routing;
5
6
use Psr\Http\Message\RequestInterface;
7
use PTS\Routing\Traits\MiddlewaresTrait;
8
9
class Route
10
{
11
    use MiddlewaresTrait;
12
13
    /** @var string */
14
    protected $path;
15
    /** @var callable */
16
    protected $endPoint;
17
    /** @var array */
18
    protected $methods = [];
19
    /** @var array */
20
    protected $restrictions = [];
21
    /** @var array */
22
    protected $matches = [];
23
24 31
    public function __construct(string $path, callable $handler)
25
    {
26 31
        $this->path = $path;
27 31
        $this->endPoint = new EndPoint($handler);
28 31
    }
29
30 12
    public function __invoke(RequestInterface $request)
31
    {
32 12
        if (\count($this->getMiddlewares()) === 0) {
33 8
            return ($this->endPoint)();
34
        }
35
36 10
        return $this->invoke($request);
37
    }
38
39 2
    public function getEndPoint(): EndPoint
40
    {
41 2
        return $this->endPoint;
42
    }
43
44 2
    public function setRestrictions(array $restrictions): self
45
    {
46 2
        $this->restrictions = $restrictions;
47 2
        return $this;
48
    }
49
50 8
    public function getRestrictions(): array
51
    {
52 8
        return $this->restrictions;
53
    }
54
55 8
    public function getPath(): string
56
    {
57 8
        return $this->path;
58
    }
59
60 4
    public function setMatches(array $values = []): self
61
    {
62 4
        $this->matches = $values;
63 4
        return $this;
64
    }
65
66 4
    public function getMatches(): array
67
    {
68 4
        return $this->matches;
69
    }
70
71 1
    public function getMethods(): array
72
    {
73 1
        return $this->methods;
74
    }
75
76 1
    public function setMethods(array $methods): self
77
    {
78 1
        $this->methods = $methods;
79 1
        return $this;
80
    }
81
}
82