1 | <?php |
||
13 | class CoalesceSingleCharacterPrefix extends AbstractPass |
||
14 | { |
||
15 | /** |
||
16 | * {@inheritdoc} |
||
17 | */ |
||
18 | 5 | protected function runPass(array $strings) |
|
19 | { |
||
20 | 5 | $newStrings = []; |
|
21 | 5 | foreach ($this->getEligibleKeys($strings) as $keys) |
|
22 | { |
||
23 | // Create a new string to hold the merged strings and replace the first element with |
||
24 | // an empty character class |
||
25 | 2 | $newString = $strings[$keys[0]]; |
|
26 | 2 | $newString[0] = []; |
|
27 | 2 | foreach ($keys as $key) |
|
28 | { |
||
29 | 2 | $newString[0][] = [$strings[$key][0]]; |
|
30 | 2 | unset($strings[$key]); |
|
31 | } |
||
32 | 2 | $newStrings[] = $newString; |
|
33 | } |
||
34 | |||
35 | 5 | return array_merge($newStrings, $strings); |
|
36 | } |
||
37 | |||
38 | /** |
||
39 | * Filter the list of eligible keys and keep those that have at least two matches |
||
40 | * |
||
41 | * @param array[] $eligibleKeys List of lists of keys |
||
42 | * @return array[] |
||
43 | */ |
||
44 | 5 | protected function filterEligibleKeys(array $eligibleKeys) |
|
57 | |||
58 | /** |
||
59 | * Get a list of keys of strings eligible to be merged together, grouped by suffix |
||
60 | * |
||
61 | * @param array[] $strings |
||
62 | * @return array[] |
||
63 | */ |
||
64 | 5 | protected function getEligibleKeys(array $strings) |
|
78 | } |