Total Complexity | 13 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | final class PathValidator |
||
10 | { |
||
11 | 105 | public function __invoke(string $path): bool |
|
12 | { |
||
13 | 105 | return $this->isPathValid($path); |
|
14 | } |
||
15 | |||
16 | 105 | protected function isPathValid(string $path): bool |
|
17 | { |
||
18 | 105 | return $this->isPathEmpty($path) || $this->isPathValidFormat($path); |
|
19 | } |
||
20 | |||
21 | 105 | private function isPathEmpty(string $path): bool |
|
22 | { |
||
23 | 105 | return $path === ''; |
|
24 | } |
||
25 | |||
26 | 104 | private function isPathValidFormat(string $path): bool |
|
27 | { |
||
28 | 104 | return $this->isPathStartWithoutSlash($path) |
|
29 | 104 | && $this->isPathEndWithoutSlash($path) |
|
30 | 104 | && $this->areOptionalArgumentsAfterMandatoryArguments($path); |
|
31 | } |
||
32 | |||
33 | 104 | private function isPathStartWithoutSlash(string $path): bool |
|
34 | { |
||
35 | 104 | return $path[0] !== '/'; |
|
36 | } |
||
37 | |||
38 | 104 | private function isPathEndWithoutSlash(string $path): bool |
|
39 | { |
||
40 | 104 | return $path[-1] !== '/'; |
|
41 | } |
||
42 | |||
43 | 104 | private function areOptionalArgumentsAfterMandatoryArguments(string $path): bool |
|
60 | } |
||
61 | } |
||
62 |