| Conditions | 3 |
| Paths | 2 |
| Total Lines | 11 |
| Code Lines | 6 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 7 |
| CRAP Score | 3 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 34 | 2 | private function compilePattern(string $topic): string |
|
| 35 | { |
||
| 36 | 2 | $replaces = []; |
|
| 37 | 2 | if (preg_match_all('/\{(\w+):?(.*?)?\}/', $topic, $matches)) { |
|
| 38 | 2 | $variables = array_combine($matches[1], $matches[2]); |
|
| 39 | 2 | foreach ($variables as $key => $_) { |
|
| 40 | 2 | $replaces['{' . $key . '}'] = '(?P<' . $key . '>[^\/\.]+)'; |
|
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | 2 | return '/^' . strtr($topic, $replaces + ['/' => '\\/', '[' => '(?:', ']' => ')?', '.' => '\.']) . '$/iu'; |
|
| 45 | } |
||
| 47 |