Conditions | 9 |
Paths | 9 |
Total Lines | 32 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Tests | 19 |
CRAP Score | 9 |
Changes | 0 |
1 | <?php |
||
11 | 109 | public static function isValid(string $path): bool |
|
12 | { |
||
13 | 109 | if ($path === '/') { |
|
14 | 2 | return true; |
|
15 | } |
||
16 | |||
17 | 109 | if ($path === '') { |
|
18 | 1 | return false; |
|
19 | } |
||
20 | |||
21 | 108 | if (str_starts_with($path, '/')) { |
|
22 | 1 | return false; |
|
23 | } |
||
24 | |||
25 | 107 | if (str_ends_with($path, '/')) { |
|
26 | 1 | return false; |
|
27 | } |
||
28 | |||
29 | 106 | $parts = explode('/', $path); |
|
30 | 106 | $optionalParamFound = false; |
|
31 | |||
32 | 106 | foreach ($parts as $part) { |
|
33 | 106 | if (!$part) { // Empty part found |
|
34 | 1 | return false; |
|
35 | 106 | } elseif (preg_match(RouteParams::OPTIONAL_PARAM_PATTERN, $part)) { // Optional argument found |
|
36 | 10 | $optionalParamFound = true; |
|
37 | 106 | } elseif ($optionalParamFound) { // Mandatory argument or static part found after an optional argument |
|
38 | 2 | return false; |
|
39 | } |
||
40 | } |
||
41 | |||
42 | 103 | return true; |
|
43 | } |
||
45 |