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