| Conditions | 4 |
| Paths | 2 |
| Total Lines | 16 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | 7 | public function makeRegExp(Route $route) : string |
|
| 10 | { |
||
| 11 | 7 | $regexp = $route->getPath(); |
|
| 12 | 7 | $restrictions = $route->getRestrictions(); |
|
| 13 | |||
| 14 | 7 | if (preg_match_all('~{(.*)}~Uu', $regexp, $placeholders)) { |
|
| 15 | 6 | foreach ($placeholders[0] as $index => $match) { |
|
| 16 | 6 | $name = $placeholders[1][$index]; |
|
| 17 | 6 | $replace = array_key_exists($name, $restrictions) ? $restrictions[$name] : '[^\/]+'; |
|
| 18 | 6 | $replace = '(?<'.$name.'>'.$replace.')'; |
|
| 19 | 6 | $regexp = str_replace($match, $replace, $regexp); |
|
| 20 | } |
||
| 21 | } |
||
| 22 | |||
| 23 | 7 | return $regexp; |
|
| 24 | } |
||
| 25 | } |
||
| 26 |