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