Complex classes like Arr often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Arr, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
33 | final class Arr |
||
34 | { |
||
35 | /** |
||
36 | * Gets a dot-notated key from an array, with a default value if it does |
||
37 | * not exist. |
||
38 | * |
||
39 | * @param array $array The search array |
||
40 | * @param string $key The dot-notated key or array of keys |
||
41 | * @param string $default The default value |
||
42 | * |
||
43 | * @return mixed |
||
44 | * |
||
45 | * @since 0.1.0 |
||
46 | * @codeCoverageIgnore |
||
47 | */ |
||
48 | public static function get(array $array, $key, $default = null) |
||
86 | |||
87 | /** |
||
88 | * Set an array item (dot-notated) to the value. |
||
89 | * |
||
90 | * @param array $array The array to insert it into |
||
91 | * @param mixed $key The dot-notated key to set or array of keys |
||
92 | * @param mixed $value The value |
||
93 | * |
||
94 | * @return void Void |
||
95 | * @since 0.1.0 |
||
96 | * @codeCoverageIgnore |
||
97 | */ |
||
98 | public static function set(array &$array, $key, $value = null) |
||
128 | |||
129 | /** |
||
130 | * Merge two arrays recursively. |
||
131 | * |
||
132 | * @throws InvalidArgumentException |
||
133 | * |
||
134 | * @return array |
||
135 | * |
||
136 | * @since 0.1.0 |
||
137 | * @codeCoverageIgnore |
||
138 | */ |
||
139 | public static function merge() |
||
176 | |||
177 | /** |
||
178 | * Merge two arrays recursively | assoc. |
||
179 | * |
||
180 | * @throws InvalidArgumentException |
||
181 | * |
||
182 | * @return array |
||
183 | * |
||
184 | * @since 0.1.0 |
||
185 | * @codeCoverageIgnore |
||
186 | */ |
||
187 | public static function mergeAssoc() |
||
219 | |||
220 | /** |
||
221 | * Un-sets dot-notated key from an array. |
||
222 | * |
||
223 | * @param array $array The search array |
||
224 | * @param mixed $key The dot-notated key or array of keys |
||
225 | * |
||
226 | * @return mixed |
||
227 | * |
||
228 | * @since 0.1.0 |
||
229 | * @codeCoverageIgnore |
||
230 | */ |
||
231 | public static function delete(array &$array, $key) |
||
267 | |||
268 | /** |
||
269 | * Get array keys recursively. |
||
270 | * |
||
271 | * @param array $array The search array |
||
272 | * @param int $maxDepth The search maximum depth |
||
273 | * @param int $depth The search depth |
||
274 | * @param array $arraykeys The array keys |
||
275 | * |
||
276 | * @return array |
||
277 | * |
||
278 | * @since 0.1.0 |
||
279 | * @codeCoverageIgnore |
||
280 | */ |
||
281 | public static function keys( |
||
304 | |||
305 | /** |
||
306 | * Get array keys recursively. |
||
307 | * |
||
308 | * @param array $array The search array |
||
309 | * @param string $search The search value |
||
310 | * |
||
311 | * @return array |
||
312 | * |
||
313 | * @since 0.1.2 |
||
314 | * @codeCoverageIgnore |
||
315 | */ |
||
316 | public static function recursiveKeys(array $array, $search = null) |
||
341 | |||
342 | /** |
||
343 | * __toString. |
||
344 | * |
||
345 | * @return string |
||
346 | * |
||
347 | * @since 0.1.2 |
||
348 | * @codeCoverageIgnore |
||
349 | */ |
||
350 | public function __toString() |
||
354 | } |
||
355 | |||
357 |