@@ -9,80 +9,80 @@ |
||
| 9 | 9 | |
| 10 | 10 | class MergeSuffix extends AbstractPass |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * {@inheritdoc} |
|
| 14 | - */ |
|
| 15 | - protected function processStrings(array $strings) |
|
| 16 | - { |
|
| 17 | - if (!$this->isEligible($strings)) |
|
| 18 | - { |
|
| 19 | - return $strings; |
|
| 20 | - } |
|
| 12 | + /** |
|
| 13 | + * {@inheritdoc} |
|
| 14 | + */ |
|
| 15 | + protected function processStrings(array $strings) |
|
| 16 | + { |
|
| 17 | + if (!$this->isEligible($strings)) |
|
| 18 | + { |
|
| 19 | + return $strings; |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - $newString = []; |
|
| 23 | - while ($this->hasMatchingSuffix($strings)) |
|
| 24 | - { |
|
| 25 | - array_unshift($newString, end($strings[0])); |
|
| 26 | - $strings = $this->pop($strings); |
|
| 27 | - } |
|
| 28 | - array_unshift($newString, $strings); |
|
| 22 | + $newString = []; |
|
| 23 | + while ($this->hasMatchingSuffix($strings)) |
|
| 24 | + { |
|
| 25 | + array_unshift($newString, end($strings[0])); |
|
| 26 | + $strings = $this->pop($strings); |
|
| 27 | + } |
|
| 28 | + array_unshift($newString, $strings); |
|
| 29 | 29 | |
| 30 | - return [$newString]; |
|
| 31 | - } |
|
| 30 | + return [$newString]; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Test whether all given strings have the same last element |
|
| 35 | - * |
|
| 36 | - * @param array[] $strings |
|
| 37 | - * @return bool |
|
| 38 | - */ |
|
| 39 | - protected function hasMatchingSuffix(array $strings) |
|
| 40 | - { |
|
| 41 | - $suffix = end($strings[1]); |
|
| 42 | - foreach ($strings as $string) |
|
| 43 | - { |
|
| 44 | - if (end($string) !== $suffix) |
|
| 45 | - { |
|
| 46 | - return false; |
|
| 47 | - } |
|
| 48 | - } |
|
| 33 | + /** |
|
| 34 | + * Test whether all given strings have the same last element |
|
| 35 | + * |
|
| 36 | + * @param array[] $strings |
|
| 37 | + * @return bool |
|
| 38 | + */ |
|
| 39 | + protected function hasMatchingSuffix(array $strings) |
|
| 40 | + { |
|
| 41 | + $suffix = end($strings[1]); |
|
| 42 | + foreach ($strings as $string) |
|
| 43 | + { |
|
| 44 | + if (end($string) !== $suffix) |
|
| 45 | + { |
|
| 46 | + return false; |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return ($suffix !== false); |
|
| 51 | - } |
|
| 50 | + return ($suffix !== false); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Test whether this pass can be run on given list of strings |
|
| 55 | - * |
|
| 56 | - * @param array[] $strings |
|
| 57 | - * @return bool |
|
| 58 | - */ |
|
| 59 | - protected function isEligible(array $strings) |
|
| 60 | - { |
|
| 61 | - return (count($strings) > 1 && $this->hasMatchingSuffix($strings)); |
|
| 62 | - } |
|
| 53 | + /** |
|
| 54 | + * Test whether this pass can be run on given list of strings |
|
| 55 | + * |
|
| 56 | + * @param array[] $strings |
|
| 57 | + * @return bool |
|
| 58 | + */ |
|
| 59 | + protected function isEligible(array $strings) |
|
| 60 | + { |
|
| 61 | + return (count($strings) > 1 && $this->hasMatchingSuffix($strings)); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Remove the last element of every string |
|
| 66 | - * |
|
| 67 | - * @param array[] $strings Original strings |
|
| 68 | - * @return array[] Processed strings |
|
| 69 | - */ |
|
| 70 | - protected function pop(array $strings) |
|
| 71 | - { |
|
| 72 | - $cnt = count($strings); |
|
| 73 | - $i = $cnt; |
|
| 74 | - while (--$i >= 0) |
|
| 75 | - { |
|
| 76 | - array_pop($strings[$i]); |
|
| 77 | - } |
|
| 64 | + /** |
|
| 65 | + * Remove the last element of every string |
|
| 66 | + * |
|
| 67 | + * @param array[] $strings Original strings |
|
| 68 | + * @return array[] Processed strings |
|
| 69 | + */ |
|
| 70 | + protected function pop(array $strings) |
|
| 71 | + { |
|
| 72 | + $cnt = count($strings); |
|
| 73 | + $i = $cnt; |
|
| 74 | + while (--$i >= 0) |
|
| 75 | + { |
|
| 76 | + array_pop($strings[$i]); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - // Remove empty elements then prepend one back at the start of the array if applicable |
|
| 80 | - $strings = array_filter($strings); |
|
| 81 | - if (count($strings) < $cnt) |
|
| 82 | - { |
|
| 83 | - array_unshift($strings, []); |
|
| 84 | - } |
|
| 79 | + // Remove empty elements then prepend one back at the start of the array if applicable |
|
| 80 | + $strings = array_filter($strings); |
|
| 81 | + if (count($strings) < $cnt) |
|
| 82 | + { |
|
| 83 | + array_unshift($strings, []); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - return $strings; |
|
| 87 | - } |
|
| 86 | + return $strings; |
|
| 87 | + } |
|
| 88 | 88 | } |
| 89 | 89 | \ No newline at end of file |