| Conditions | 1 |
| Paths | 1 |
| Total Lines | 15 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 44 | function fnmatch_extended($pattern, $path) |
||
| 45 | { |
||
| 46 | $quoted = preg_quote($pattern, '~'); |
||
| 47 | |||
| 48 | $step1 = strtr($quoted, ['\?' => '[^/]', '\*' => '[^/]*', '/\*\*' => '(?:/.*)?', '#' => '\d+', '\[' => '[', |
||
| 49 | '\]' => ']', '\-' => '-', '\{' => '{', '\}' => '}']); |
||
| 50 | |||
| 51 | $step2 = preg_replace_callback('~{[^}]+}~', function ($part) { |
||
| 52 | return '(?:' . substr(strtr($part[0], ',', '|'), 1, -1) . ')'; |
||
| 53 | }, $step1); |
||
| 54 | |||
| 55 | $regex = rawurldecode($step2); |
||
| 56 | |||
| 57 | return (boolean)preg_match("~^{$regex}$~", $path); |
||
| 58 | } |
||
| 59 |
Adding braces to control structures avoids accidental mistakes as your code changes: