Route   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 15
lcom 2
cbo 0
dl 0
loc 98
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 1
A buildRealUri() 0 9 3
A withAliases() 0 6 1
A withStatusCode() 0 6 1
A getStatusCode() 0 4 1
A getReturnType() 0 4 1
A getController() 0 4 1
A getRequestMethod() 0 4 1
A getPattern() 0 4 1
A getRealUri() 0 4 1
A getUriParameters() 0 4 1
A getAliases() 0 4 1
A getAlias() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Selami\Router;
5
6
class Route
7
{
8
    private $requestMethod;
9
    private $statusCode;
10
    private $returnType;
11
    private $pattern;
12
    private $uriParameters;
13
    private $aliases;
14
    private $controller;
15
    private $realUri;
16
17
    public function __construct(
18
        string $requestMethod,
19
        string $pattern,
20
        int $statusCode,
21
        int $returnType,
22
        string $controller,
23
        array $uriParameters
24
    ) {
25
        $this->requestMethod = $requestMethod;
26
        $this->pattern = $pattern;
27
        $this->statusCode = $statusCode;
28
        $this->returnType = $returnType;
29
        $this->controller = $controller;
30
        $this->uriParameters = $uriParameters;
31
        $this->aliases = [];
32
        $this->realUri = $this->buildRealUri($pattern, $uriParameters);
33
    }
34
35
    private function buildRealUri($pattern, $uriParameters) : string
36
    {
37
        if (count($uriParameters) > 0) {
38
            foreach ($uriParameters as $key => $value) {
39
                $pattern = preg_replace('/{'.$key.'(.*?)}/msi', $value, $pattern);
40
            }
41
        }
42
        return $pattern;
43
    }
44
45
    public function withAliases(array $aliases) : self
46
    {
47
        $new = clone $this;
48
        $new->aliases = $aliases;
49
        return $new;
50
    }
51
    
52
    public function withStatusCode(int $statusCode) : self
53
    {
54
        $new = clone $this;
55
        $new->statusCode = $statusCode;
56
        return $new;
57
    }
58
59
    public function getStatusCode() : int
60
    {
61
        return $this->statusCode;
62
    }
63
64
    public function getReturnType() : int
65
    {
66
        return $this->returnType;
67
    }
68
69
    public function getController() : string
70
    {
71
        return $this->controller;
72
    }
73
74
    public function getRequestMethod() : string
75
    {
76
        return $this->requestMethod;
77
    }
78
79
    public function getPattern() : string
80
    {
81
        return $this->pattern;
82
    }
83
84
    public function getRealUri() : string
85
    {
86
        return $this->realUri;
87
    }
88
89
    public function getUriParameters() : array
90
    {
91
        return $this->uriParameters;
92
    }
93
94
    public function getAliases() : array
95
    {
96
        return $this->aliases;
97
    }
98
99
    public function getAlias(string $name) : string
100
    {
101
        return $this->aliases[$name] ?? '';
102
    }
103
}
104