Passed
Branch master (701f59)
by Alexpts
02:08
created

Route::setMatches()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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