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 |
||
31 | final class Arr |
||
32 | { |
||
33 | /** |
||
34 | * Gets a dot-notated key from an array, with a default value if it does |
||
35 | * not exist. |
||
36 | * |
||
37 | * @param array $array The search array |
||
38 | * @param string $key The dot-notated key or array of keys |
||
39 | * @param string $default The default value |
||
40 | * |
||
41 | * @return mixed |
||
42 | * |
||
43 | * @since 0.1.0 |
||
44 | * @codeCoverageIgnore |
||
45 | */ |
||
46 | public static function get(array $array, $key, $default = null) |
||
84 | |||
85 | /** |
||
86 | * Set an array item (dot-notated) to the value. |
||
87 | * |
||
88 | * @param array $array The array to insert it into |
||
89 | * @param mixed $key The dot-notated key to set or array of keys |
||
90 | * @param mixed $value The value |
||
91 | * |
||
92 | * @return void Void |
||
93 | * @since 0.1.0 |
||
94 | * @codeCoverageIgnore |
||
95 | */ |
||
96 | public static function set(array &$array, $key, $value = null) |
||
126 | |||
127 | /** |
||
128 | * Merge two arrays recursively. |
||
129 | * |
||
130 | * @throws InvalidArgumentException |
||
131 | * |
||
132 | * @return array |
||
133 | * |
||
134 | * @since 0.1.0 |
||
135 | * @codeCoverageIgnore |
||
136 | */ |
||
137 | public static function merge() |
||
174 | |||
175 | /** |
||
176 | * Merge two arrays recursively | assoc. |
||
177 | * |
||
178 | * @throws InvalidArgumentException |
||
179 | * |
||
180 | * @return array |
||
181 | * |
||
182 | * @since 0.1.0 |
||
183 | * @codeCoverageIgnore |
||
184 | */ |
||
185 | public static function mergeAssoc() |
||
217 | |||
218 | /** |
||
219 | * Un-sets dot-notated key from an array. |
||
220 | * |
||
221 | * @param array $array The search array |
||
222 | * @param mixed $key The dot-notated key or array of keys |
||
223 | * |
||
224 | * @return mixed |
||
225 | * |
||
226 | * @since 0.1.0 |
||
227 | * @codeCoverageIgnore |
||
228 | */ |
||
229 | public static function delete(array &$array, $key) |
||
264 | |||
265 | /** |
||
266 | * __toString. |
||
267 | * |
||
268 | * @return string |
||
269 | * @since 0.1.2 |
||
270 | * @codeCoverageIgnore |
||
271 | */ |
||
272 | public function __toString() |
||
276 | } |
||
277 | |||
279 |