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 | 2 | public static function get_dependencies ($meta, $update = false) { |
|
83 | /** |
||
84 | * @param array $dependencies |
||
85 | * @param array $meta |
||
86 | * @param array $component_meta |
||
87 | * @param bool $update |
||
88 | */ |
||
89 | 2 | protected static function common_checks (&$dependencies, &$meta, $component_meta, $update) { |
|
150 | /** |
||
151 | * Check whether there is available supported DB engine |
||
152 | * |
||
153 | * @param string[] $db_support |
||
154 | * |
||
155 | * @return bool |
||
156 | */ |
||
157 | 2 | protected static function check_dependencies_db ($db_support) { |
|
176 | /** |
||
177 | * Check whether there is available supported Storage engine |
||
178 | * |
||
179 | * @param string[] $storage_support |
||
180 | * |
||
181 | * @return bool |
||
182 | */ |
||
183 | 2 | protected static function check_dependencies_storage ($storage_support) { |
|
202 | /** |
||
203 | * Check if two both components are the same |
||
204 | * |
||
205 | * @param array $new_meta `meta.json` content of new component |
||
206 | * @param array $existing_meta `meta.json` content of existing component |
||
207 | * |
||
208 | * @return bool |
||
209 | */ |
||
210 | 2 | protected static function check_dependencies_are_the_same ($new_meta, $existing_meta) { |
|
215 | /** |
||
216 | * Check for functionality provided by other components |
||
217 | * |
||
218 | * @param array $new_meta `meta.json` content of new component |
||
219 | * @param array $existing_meta `meta.json` content of existing component |
||
220 | * |
||
221 | * @return array |
||
222 | */ |
||
223 | 2 | protected static function also_provided_by ($new_meta, $existing_meta) { |
|
226 | /** |
||
227 | * Check whether other component is required and have satisfactory version |
||
228 | * |
||
229 | * @param array $new_meta `meta.json` content of new component |
||
230 | * @param array $existing_meta `meta.json` content of existing component |
||
231 | * |
||
232 | * @return array |
||
233 | */ |
||
234 | 2 | protected static function check_requirement ($new_meta, $existing_meta) { |
|
245 | /** |
||
246 | * Check whether other component is required and have satisfactory version |
||
247 | * |
||
248 | * @param array $requirements |
||
249 | * @param string $component |
||
250 | * @param string $version |
||
251 | * @param bool $should_satisfy `true` for conflicts detection and `false` for requirements to fail |
||
252 | * |
||
253 | * @return array |
||
254 | */ |
||
255 | 2 | protected static function check_conflicts_or_requirements ($requirements, $component, $version, $should_satisfy) { |
|
273 | /** |
||
274 | * Check for if component conflicts other components |
||
275 | * |
||
276 | * @param array $new_meta `meta.json` content of new component |
||
277 | * @param array $existing_meta `meta.json` content of existing component |
||
278 | * |
||
279 | * @return array |
||
280 | */ |
||
281 | 2 | protected static function check_conflicts ($new_meta, $existing_meta) { |
|
292 | /** |
||
293 | * @param array $meta_from |
||
294 | * @param array $meta_to |
||
295 | * |
||
296 | * @return array |
||
297 | */ |
||
298 | 2 | protected static function conflicts_one_step ($meta_from, $meta_to) { |
|
312 | /** |
||
313 | * Check whether package is currently used by any other package (during uninstalling/disabling) |
||
314 | * |
||
315 | * @param array $meta `meta.json` contents of target component |
||
316 | * |
||
317 | * @return string[][] Empty array if dependencies are fine or array with optional key `modules` that contain array of dependent packages |
||
318 | */ |
||
319 | 2 | public static function get_dependent_packages ($meta) { |
|
360 | /** |
||
361 | * Normalize structure of `meta.json` |
||
362 | * |
||
363 | * 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 |
||
364 | * |
||
365 | * @param array $meta |
||
366 | * |
||
367 | * @return array mixed |
||
368 | */ |
||
369 | 2 | protected static function normalize_meta ($meta) { |
|
378 | /** |
||
379 | * Function for normalization of dependencies structure |
||
380 | * |
||
381 | * @param array|string $dependence_structure |
||
382 | * |
||
383 | * @return array |
||
384 | */ |
||
385 | 2 | protected static function dep_normal ($dependence_structure) { |
|
397 | } |
||
398 |