| Conditions | 3 |
| Paths | 4 |
| Total Lines | 21 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 37 | public function sanitize(string $filename): string |
||
| 38 | { |
||
| 39 | $percents = []; |
||
| 40 | |||
| 41 | foreach (self::EXPECTED_FILENAMES as $expected) { |
||
| 42 | $percents[$expected] = similar_text($expected, $filename); |
||
| 43 | } |
||
| 44 | |||
| 45 | $maxVal = max($percents); |
||
| 46 | $maxValKeys = array_keys($percents, $maxVal, true); |
||
| 47 | |||
| 48 | if (count($maxValKeys) > 1) { |
||
| 49 | throw new RuntimeException(sprintf( |
||
| 50 | 'When using "%s", which filename do you mean [%s]?', |
||
| 51 | $filename, |
||
| 52 | implode(' or ', $maxValKeys), |
||
| 53 | )); |
||
| 54 | } |
||
| 55 | |||
| 56 | /** @psalm-suppress RedundantCast */ |
||
| 57 | return (string)reset($maxValKeys); |
||
| 58 | } |
||
| 60 |