Route   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 2
dl 0
loc 73
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __invoke() 0 8 2
A getEndPoint() 0 4 1
A setRestrictions() 0 5 1
A getRestrictions() 0 4 1
A getPath() 0 4 1
A setMatches() 0 5 1
A getMatches() 0 4 1
A getMethods() 0 4 1
A setMethods() 0 5 1
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