Complex classes like Packages_dependencies 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 Packages_dependencies, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
18 | class Packages_dependencies { |
||
19 | /** |
||
20 | * Check dependencies for new component (during installation/updating/enabling) |
||
21 | * |
||
22 | * @param array $meta `meta.json` contents of target component |
||
23 | * @param bool $update Is this for updating component to newer version (`$meta` will correspond to the version that components is going to be updated to) |
||
24 | * |
||
25 | * @return array |
||
26 | */ |
||
27 | static function get_dependencies ($meta, $update = false) { |
||
79 | /** |
||
80 | * @param array $dependencies |
||
81 | * @param array $meta |
||
82 | * @param array $component_meta |
||
83 | * @param bool $update |
||
84 | */ |
||
85 | protected static function common_checks (&$dependencies, &$meta, $component_meta, $update) { |
||
160 | /** |
||
161 | * Check whether there is available supported DB engine |
||
162 | * |
||
163 | * @param string[] $db_support |
||
164 | * |
||
165 | * @return bool |
||
166 | */ |
||
167 | protected static function check_dependencies_db ($db_support) { |
||
186 | /** |
||
187 | * Check whether there is available supported Storage engine |
||
188 | * |
||
189 | * @param string[] $storage_support |
||
190 | * |
||
191 | * @return bool |
||
192 | */ |
||
193 | protected static function check_dependencies_storage ($storage_support) { |
||
212 | /** |
||
213 | * Check if two both components are the same |
||
214 | * |
||
215 | * @param array $new_meta `meta.json` content of new component |
||
216 | * @param array $existing_meta `meta.json` content of existing component |
||
217 | * |
||
218 | * @return bool |
||
219 | */ |
||
220 | protected static function check_dependencies_are_the_same ($new_meta, $existing_meta) { |
||
225 | /** |
||
226 | * Check for functionality provided by other components |
||
227 | * |
||
228 | * @param array $new_meta `meta.json` content of new component |
||
229 | * @param array $existing_meta `meta.json` content of existing component |
||
230 | * |
||
231 | * @return array |
||
232 | */ |
||
233 | protected static function also_provided_by ($new_meta, $existing_meta) { |
||
236 | /** |
||
237 | * Check whether other component is required and have satisfactory version |
||
238 | * |
||
239 | * @param array $new_meta `meta.json` content of new component |
||
240 | * @param array $existing_meta `meta.json` content of existing component |
||
241 | * |
||
242 | * @return array |
||
243 | */ |
||
244 | protected static function check_requirement_satisfaction ($new_meta, $existing_meta) { |
||
247 | /** |
||
248 | * Check whether other component is required and have satisfactory version |
||
249 | * |
||
250 | * @param array $requirements |
||
251 | * @param string $component |
||
252 | * @param string $version |
||
253 | * |
||
254 | * @return array |
||
255 | */ |
||
256 | protected static function check_conflicts ($requirements, $component, $version) { |
||
274 | /** |
||
275 | * Check for if component conflicts other components |
||
276 | * |
||
277 | * @param array $new_meta `meta.json` content of new component |
||
278 | * @param array $existing_meta `meta.json` content of existing component |
||
279 | * |
||
280 | * @return array |
||
281 | */ |
||
282 | protected static function conflicts ($new_meta, $existing_meta) { |
||
293 | /** |
||
294 | * @param array $meta_from |
||
295 | * @param array $meta_to |
||
296 | * |
||
297 | * @return array |
||
298 | */ |
||
299 | protected static function conflicts_one_step ($meta_from, $meta_to) { |
||
310 | /** |
||
311 | * Check whether package is currently used by any other package (during uninstalling/disabling) |
||
312 | * |
||
313 | * @param array $meta `meta.json` contents of target component |
||
314 | * |
||
315 | * @return string[][] Empty array if dependencies are fine or array with optional key `modules` that contain array of dependent packages |
||
316 | */ |
||
317 | static function get_dependent_packages ($meta) { |
||
358 | /** |
||
359 | * Normalize structure of `meta.json` |
||
360 | * |
||
361 | * Addition necessary items if they are not present and casting some string values to arrays in order to decrease number of checks in further code |
||
362 | * |
||
363 | * @param array $meta |
||
364 | * |
||
365 | * @return array mixed |
||
366 | */ |
||
367 | protected static function normalize_meta ($meta) { |
||
376 | /** |
||
377 | * Function for normalization of dependencies structure |
||
378 | * |
||
379 | * @param array|string $dependence_structure |
||
380 | * |
||
381 | * @return array |
||
382 | */ |
||
383 | protected static function dep_normal ($dependence_structure) { |
||
395 | } |
||
396 |