Completed
Push — master ( 3528ad...ff9b79 )
by Alexpts
02:31
created

Route::setGroup()   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
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
namespace PTS\Routing;
3
4
use Psr\Http\Message\RequestInterface;
5
use PTS\Routing\Traits\MiddlewaresTrait;
6
7
class Route
8
{
9
    use MiddlewaresTrait;
10
11
    /** @var string */
12
    protected $path;
13
    /** @var callable */
14
    protected $endPoint;
15
    /** @var array */
16
    protected $methods = [];
17
    /** @var array */
18
    protected $restrictions = [];
19
    /** @var array */
20
    protected $matches = [];
21
22
    /**
23
     * @param string $path
24
     * @param callable $handler
25
     */
26 34
    public function __construct(string $path, callable $handler)
27
    {
28 34
        $this->path = $path;
29 34
        $this->endPoint = new EndPoint($handler);
30 34
    }
31
32
    /**
33
     * @param RequestInterface $request
34
     * @return mixed
35
     */
36 16
    public function __invoke(RequestInterface $request)
37
    {
38 16
        if (count($this->getMiddlewares()) === 0) {
39 12
            return $this->endPoint();
0 ignored issues
show
Bug introduced by
The method endPoint() does not exist on PTS\Routing\Route. Did you maybe mean getEndPoint()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
40
        }
41
42 15
        return $this->invoke($request);
43
    }
44
45
    /**
46
     * @return EndPoint
47
     */
48 7
    public function getEndPoint() : EndPoint
49
    {
50 7
        return $this->endPoint;
51
    }
52
53
    /**
54
     * @param array $restrictions
55
     * @return $this
56
     */
57 2
    public function setRestrictions(array $restrictions)
58
    {
59 2
        $this->restrictions = $restrictions;
60 2
        return $this;
61
    }
62
63
    /**
64
     * @return array
65
     */
66 12
    public function getRestrictions() : array
67
    {
68 12
        return $this->restrictions;
69
    }
70
71
    /**
72
     * @return string
73
     */
74 12
    public function getPath() : string
75
    {
76 12
        return $this->path;
77
    }
78
79
    /**
80
     * @param array $values
81
     * @return $this
82
     */
83 8
    public function setMatches(array $values = [])
84
    {
85 8
        $this->matches = $values;
86 8
        return $this;
87
    }
88
89
    /**
90
     * @return array
91
     */
92 7
    public function getMatches() : array
93
    {
94 7
        return $this->matches;
95
    }
96
97
    /**
98
     * @return array
99
     */
100 1
    public function getMethods() : array
101
    {
102 1
        return $this->methods;
103
    }
104
105
    /**
106
     * @param array $methods
107
     * @return $this
108
     */
109 1
    public function setMethods(array $methods)
110
    {
111 1
        $this->methods = $methods;
112 1
        return $this;
113
    }
114
}
115