Conditions | 4 |
Paths | 5 |
Total Lines | 26 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
9 | public function extractPlaceholders(Request $request, $pathPattern) |
||
10 | { |
||
11 | preg_match_all('#\{\w+\}#', $pathPattern, $placeholders, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); |
||
12 | |||
13 | if (!count($placeholders)) { |
||
14 | return array(); |
||
15 | } |
||
16 | |||
17 | $placeholderNames = array(); |
||
18 | foreach ($placeholders as $placeholderMatch) { |
||
|
|||
19 | $placeholder = $placeholderMatch[0][0]; |
||
20 | $placeholderNames[] = substr($placeholder, 1, -1); |
||
21 | $pathPattern = str_replace($placeholder, '__PLACEHOLDER__', $pathPattern); |
||
22 | } |
||
23 | |||
24 | $pathPattern = '/^' . str_replace('__PLACEHOLDER__', '([^\/]*)', preg_quote($pathPattern, '/')) . '$/i'; |
||
25 | |||
26 | if (0 === preg_match($pathPattern, $request->getPathInfo(), $matches)) { |
||
27 | return array(); |
||
28 | } |
||
29 | |||
30 | return array_combine( |
||
31 | $placeholderNames, |
||
32 | array_slice($matches, 1, count($placeholders)) |
||
33 | ); |
||
34 | } |
||
35 | } |
||
36 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.