1 | <?php |
||
10 | class ShortestCommonSuperstring |
||
11 | { |
||
12 | /** |
||
13 | * @var integer Affix length for current iteration |
||
14 | */ |
||
15 | protected $len; |
||
16 | |||
17 | /** |
||
18 | * @var string[] Prefixes of current length |
||
19 | */ |
||
20 | protected $prefixes; |
||
21 | |||
22 | /** |
||
23 | * @var string[] Strings being merged |
||
24 | */ |
||
25 | protected $strings; |
||
26 | |||
27 | /** |
||
28 | * @var string[] Suffixes of current length |
||
29 | */ |
||
30 | protected $suffixes; |
||
31 | |||
32 | /** |
||
33 | * Get the shortest string that contains all given strings |
||
34 | * |
||
35 | * @param string[] $strings |
||
36 | * @return string |
||
37 | */ |
||
38 | 11 | public function getShortest(array $strings) |
|
55 | |||
56 | /** |
||
57 | * Compare strings |
||
58 | * |
||
59 | * @param string $a |
||
60 | * @param string $b |
||
61 | * @return integer |
||
62 | */ |
||
63 | 9 | protected static function compareStrings($a, $b) |
|
76 | |||
77 | /** |
||
78 | * Return the list of keys pointing to strings whose prefix is identical to their suffix |
||
79 | * |
||
80 | * @return integer[] |
||
81 | */ |
||
82 | 9 | protected function getIdenticalAffixKeys() |
|
95 | |||
96 | /** |
||
97 | * Match and merge a string by key |
||
98 | * |
||
99 | * @param integer $leftKey Left string's key |
||
100 | * @return bool Whether a match was found and strings merged |
||
101 | */ |
||
102 | 9 | protected function mergeString($leftKey) |
|
117 | |||
118 | /** |
||
119 | * Merge two stored strings together at current affix length |
||
120 | * |
||
121 | * @param integer $leftKey Left string's key |
||
122 | * @param integer $rightKey Right string's key |
||
123 | * @return void |
||
124 | */ |
||
125 | 7 | protected function mergeStringPair($leftKey, $rightKey) |
|
131 | |||
132 | /** |
||
133 | * Merge all stored strings using current affix length |
||
134 | * |
||
135 | * @return void |
||
136 | */ |
||
137 | 9 | protected function mergeStrings() |
|
151 | |||
152 | /** |
||
153 | * Match and merge strings from given group |
||
154 | * |
||
155 | * @param integer[] $keys List of keys |
||
156 | * @return void |
||
157 | */ |
||
158 | 9 | protected function mergeStringsGroup(array $keys) |
|
171 | |||
172 | /** |
||
173 | * Remove empty strings from the list |
||
174 | * |
||
175 | * @return void |
||
176 | */ |
||
177 | 11 | protected function removeEmptyStrings() |
|
184 | |||
185 | /** |
||
186 | * Remove fully-overlapping strings from the list |
||
187 | * |
||
188 | * @return void |
||
189 | */ |
||
190 | 11 | protected function removeFullyOverlappingStrings() |
|
208 | |||
209 | /** |
||
210 | * Reset the keys in the string list to remove the gaps |
||
211 | * |
||
212 | * @return void |
||
213 | */ |
||
214 | 11 | protected function resetKeys() |
|
222 | |||
223 | /** |
||
224 | * Sort the stored strings |
||
225 | * |
||
226 | * @return void |
||
227 | */ |
||
228 | 11 | protected function sortStrings() |
|
232 | |||
233 | /** |
||
234 | * Capture and stored affixes of current length |
||
235 | * |
||
236 | * Will only store affixes from strings that are longer than current affix length |
||
237 | * |
||
238 | * @return void |
||
239 | */ |
||
240 | 9 | protected function storeAffixes() |
|
254 | } |
This check looks for
while
loops that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.Consider removing the loop.