| Conditions | 3 |
| Paths | 4 |
| Total Lines | 20 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 3 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 32 | 24 | public function sanitize(string $filename): string |
|
| 33 | { |
||
| 34 | 24 | $percents = []; |
|
| 35 | |||
| 36 | 24 | foreach (self::EXPECTED_FILENAMES as $expected) { |
|
| 37 | 24 | $percents[$expected] = similar_text($expected, $filename, $percent); |
|
| 38 | } |
||
| 39 | |||
| 40 | 24 | $maxVal = max($percents); |
|
| 41 | 24 | $maxValKeys = array_keys($percents, $maxVal, true); |
|
| 42 | |||
| 43 | 24 | if (count($maxValKeys) > 1) { |
|
| 44 | 1 | throw new RuntimeException(sprintf( |
|
| 45 | 'When using "%s", which filename do you mean [%s]?', |
||
| 46 | $filename, |
||
| 47 | 1 | implode(' or ', $maxValKeys) |
|
| 48 | )); |
||
| 49 | } |
||
| 50 | |||
| 51 | 23 | return reset($maxValKeys); |
|
| 52 | } |
||
| 54 |