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