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 |
||
18 | final class Arr |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * Gets a dot-notated key from an array, with a default value if it does |
||
23 | * not exist. |
||
24 | * |
||
25 | * @param array $array The search array |
||
26 | * @param mixed $key The dot-notated key or array of keys |
||
27 | * @param string $default The default value |
||
28 | * @return mixed |
||
29 | * @since 0.1.0 |
||
30 | */ |
||
31 | public static function get(array $array, $key, $default = null) |
||
63 | |||
64 | /** |
||
65 | * Set an array item (dot-notated) to the value. |
||
66 | * |
||
67 | * @param array $array The array to insert it into |
||
68 | * @param mixed $key The dot-notated key to set or array of keys |
||
69 | * @param mixed $value The value |
||
70 | * @return void |
||
71 | * @since 0.1.0 |
||
72 | */ |
||
73 | public static function set(&$array, $key, $value = null) |
||
100 | |||
101 | /** |
||
102 | * Merge two arrays recursively, differs in two important ways from array_merge_recursive() |
||
103 | * - When there's two different values and not both arrays, the latter value overwrites the earlier |
||
104 | * instead of merging both into an array |
||
105 | * - Numeric keys that don't conflict aren't changed, only when a numeric key already exists is the |
||
106 | * value added using array_push() |
||
107 | * |
||
108 | * @param array multiple variables all of which must be arrays |
||
109 | * @throws InvalidArgumentException |
||
110 | * @return array |
||
111 | * @since 0.1.0 |
||
112 | */ |
||
113 | public static function merge() |
||
141 | |||
142 | /** |
||
143 | * Merge 2 arrays recursively, differs in 2 important ways from array_merge_recursive() |
||
144 | * - When there's 2 different values and not both arrays, the latter value overwrites the earlier |
||
145 | * instead of merging both into an array |
||
146 | * - Numeric keys are never changed |
||
147 | * |
||
148 | * @param array multiple variables all of which must be arrays |
||
149 | * @throws InvalidArgumentException |
||
150 | * @return array |
||
151 | * @since 0.1.0 |
||
152 | */ |
||
153 | public static function mergeAssoc() |
||
178 | |||
179 | /** |
||
180 | * Un-sets dot-notated key from an array |
||
181 | * |
||
182 | * @param array $array The search array |
||
183 | * @param mixed $key The dot-notated key or array of keys |
||
184 | * @return mixed |
||
185 | * @since 0.1.0 |
||
186 | */ |
||
187 | public static function delete(array &$array, $key) |
||
220 | |||
221 | /** |
||
222 | * Get array keys recursively |
||
223 | * |
||
224 | * @param array $array The search array |
||
225 | * @param int $maxDepth The search maximum depth |
||
226 | * @param int $depth The search depth |
||
227 | * @param array $arraykeys The array keys |
||
228 | * @return array |
||
229 | * @since 0.1.0 |
||
230 | */ |
||
231 | public static function keys(array $array, $maxDepth = INF, $depth = 0, array $arraykeys = []) |
||
246 | |||
247 | /** |
||
248 | * Get array keys recursively |
||
249 | * |
||
250 | * @param array $array The search array |
||
251 | * @param type $search The search value |
||
252 | * @return array |
||
253 | * @since 0.1.2 |
||
254 | */ |
||
255 | public static function recursiveKeys(array $array, $search = null) |
||
275 | |||
276 | /** |
||
277 | * @return string |
||
278 | * @since 0.1.2 |
||
279 | */ |
||
280 | public function __toString() |
||
284 | } |
||
285 | |||
287 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.