Complex classes like ProjectConfig 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 ProjectConfig, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 16 | class ProjectConfig |
||
| 17 | { |
||
| 18 | // Config Keys |
||
| 19 | const EXTRA_KEY = 'extra'; |
||
| 20 | |||
| 21 | const SORT_PRIORITY_KEY = 'magento-deploy-sort-priority'; |
||
| 22 | |||
| 23 | const MAGENTO_ROOT_DIR_KEY = 'magento-root-dir'; |
||
| 24 | |||
| 25 | const MAGENTO_PROJECT_KEY = 'magento-project'; |
||
| 26 | |||
| 27 | const MAGENTO_DEPLOY_STRATEGY_KEY = 'magento-deploystrategy'; |
||
| 28 | const MAGENTO_DEPLOY_STRATEGY_OVERWRITE_KEY = 'magento-deploystrategy-overwrite'; |
||
| 29 | const MAGENTO_MAP_OVERWRITE_KEY = 'magento-map-overwrite'; |
||
| 30 | const MAGENTO_DEPLOY_IGNORE_KEY = 'magento-deploy-ignore'; |
||
| 31 | |||
| 32 | const MAGENTO_FORCE_KEY = 'magento-force'; |
||
| 33 | |||
| 34 | const AUTO_APPEND_GITIGNORE_KEY = 'auto-append-gitignore'; |
||
| 35 | |||
| 36 | const PATH_MAPPINGS_TRANSLATIONS_KEY = 'path-mapping-translations'; |
||
| 37 | |||
| 38 | const INCLUDE_ROOT_PACKAGE_KEY = 'include-root-package'; |
||
| 39 | |||
| 40 | // Default Values |
||
| 41 | const DEFAULT_MAGENTO_ROOT_DIR = 'root'; |
||
| 42 | |||
| 43 | const EXTRA_WITH_BOOTSTRAP_PATCH_KEY = 'with-bootstrap-patch'; |
||
| 44 | |||
| 45 | const EXTRA_WITH_SKIP_SUGGEST_KEY = 'skip-suggest-repositories'; |
||
| 46 | |||
| 47 | protected $libraryPath; |
||
| 48 | protected $libraryPackages; |
||
| 49 | protected $extra; |
||
| 50 | protected $composerConfig; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @param array $extra |
||
| 54 | * @param array $composerConfig |
||
| 55 | */ |
||
| 56 | 32 | public function __construct(array $extra, array $composerConfig) |
|
| 65 | |||
| 66 | /** |
||
| 67 | * @param array $array |
||
| 68 | * @param string|integer $key |
||
| 69 | * @param mixed $default |
||
| 70 | * |
||
| 71 | * @return mixed |
||
| 72 | */ |
||
| 73 | 32 | protected function fetchVarFromConfigArray($array, $key, $default = null) |
|
| 83 | |||
| 84 | /** |
||
| 85 | * @param $key |
||
| 86 | * @param null $default |
||
| 87 | * |
||
| 88 | * @return null |
||
| 89 | */ |
||
| 90 | 29 | protected function fetchVarFromExtraConfig($key, $default = null) |
|
| 94 | |||
| 95 | /** |
||
| 96 | * @param $config |
||
| 97 | */ |
||
| 98 | protected function applyMagentoConfig($config) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @return mixed |
||
| 106 | */ |
||
| 107 | 3 | public function getLibraryPath() |
|
| 111 | |||
| 112 | /** |
||
| 113 | * @param $packagename |
||
| 114 | * |
||
| 115 | * @return null |
||
| 116 | */ |
||
| 117 | public function getLibraryConfigByPackagename($packagename) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @return string |
||
| 124 | */ |
||
| 125 | 20 | public function getMagentoRootDir() |
|
| 137 | |||
| 138 | /** |
||
| 139 | * @param $rootDir |
||
| 140 | */ |
||
| 141 | public function setMagentoRootDir($rootDir) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @return bool |
||
| 148 | */ |
||
| 149 | 3 | public function hasMagentoRootDir() |
|
| 153 | |||
| 154 | public function getMagentoVarDir() |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @param $deployStrategy |
||
| 161 | */ |
||
| 162 | public function setDeployStrategy($deployStrategy) |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @return string |
||
| 169 | */ |
||
| 170 | 11 | public function getDeployStrategy() |
|
| 174 | |||
| 175 | /** |
||
| 176 | * @return bool |
||
| 177 | */ |
||
| 178 | public function hasDeployStrategy() |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @return array |
||
| 185 | */ |
||
| 186 | 6 | public function getDeployStrategyOverwrite() |
|
| 192 | |||
| 193 | /** |
||
| 194 | * @return bool |
||
| 195 | */ |
||
| 196 | 6 | public function hasDeployStrategyOverwrite() |
|
| 200 | |||
| 201 | /** |
||
| 202 | * @param $packagename |
||
| 203 | * |
||
| 204 | * @return integer |
||
| 205 | */ |
||
| 206 | 5 | public function getModuleSpecificDeployStrategy($packagename) |
|
| 216 | |||
| 217 | /** |
||
| 218 | * @param $packagename |
||
| 219 | * |
||
| 220 | * @return integer |
||
| 221 | */ |
||
| 222 | 1 | public function getModuleSpecificSortValue($packagename) |
|
| 235 | |||
| 236 | /** |
||
| 237 | * @return array |
||
| 238 | */ |
||
| 239 | public function getMagentoDeployIgnore() |
||
| 245 | |||
| 246 | /** |
||
| 247 | * @param $packagename |
||
| 248 | * |
||
| 249 | * @return array |
||
| 250 | */ |
||
| 251 | 11 | public function getModuleSpecificDeployIgnores($packagename) |
|
| 268 | |||
| 269 | /** |
||
| 270 | * @return bool |
||
| 271 | */ |
||
| 272 | 11 | public function hasMagentoDeployIgnore() |
|
| 276 | |||
| 277 | /** |
||
| 278 | * @param $magentoForce |
||
| 279 | */ |
||
| 280 | public function setMagentoForce($magentoForce) |
||
| 284 | |||
| 285 | /** |
||
| 286 | * @return string |
||
| 287 | */ |
||
| 288 | 11 | public function getMagentoForce() |
|
| 292 | |||
| 293 | /** |
||
| 294 | * @return bool |
||
| 295 | */ |
||
| 296 | public function hasMagentoForce() |
||
| 300 | |||
| 301 | 11 | public function getMagentoForceByPackageName($packagename) |
|
| 305 | |||
| 306 | /** |
||
| 307 | * @return bool |
||
| 308 | */ |
||
| 309 | 6 | public function hasAutoAppendGitignore() |
|
| 313 | |||
| 314 | /** |
||
| 315 | * @return array |
||
| 316 | */ |
||
| 317 | 1 | public function getPathMappingTranslations() |
|
| 321 | |||
| 322 | /** |
||
| 323 | * @return bool |
||
| 324 | */ |
||
| 325 | 2 | public function hasPathMappingTranslations() |
|
| 329 | |||
| 330 | /** |
||
| 331 | * @return array |
||
| 332 | */ |
||
| 333 | public function getMagentoDeployOverwrite() |
||
| 339 | |||
| 340 | 5 | public function getMagentoMapOverwrite() |
|
| 350 | |||
| 351 | /** |
||
| 352 | * @param $key |
||
| 353 | * @param $value |
||
| 354 | */ |
||
| 355 | protected function updateExtraConfig($key, $value) |
||
| 360 | |||
| 361 | /** |
||
| 362 | * @throws \Exception |
||
| 363 | */ |
||
| 364 | protected function updateExtraJson() |
||
| 396 | |||
| 397 | /** |
||
| 398 | * @param JsonFile $json |
||
| 399 | * @param array $base |
||
| 400 | * @param array $new |
||
| 401 | * @param $rootKey |
||
| 402 | * |
||
| 403 | * @return bool |
||
| 404 | */ |
||
| 405 | private function updateFileCleanly(JsonFile $json, array $base, array $new, $rootKey) |
||
| 421 | |||
| 422 | /** |
||
| 423 | * @param array $array |
||
| 424 | * |
||
| 425 | * @return array |
||
| 426 | */ |
||
| 427 | 11 | public function transformArrayKeysToLowerCase(array $array) |
|
| 431 | |||
| 432 | 5 | public function getComposerRepositories() |
|
| 436 | |||
| 437 | /** |
||
| 438 | * Get Composer vendor directory |
||
| 439 | * |
||
| 440 | * @return string |
||
| 441 | */ |
||
| 442 | 7 | public function getVendorDir() |
|
| 450 | |||
| 451 | /** |
||
| 452 | * @return boolean |
||
| 453 | */ |
||
| 454 | 8 | public function mustApplyBootstrapPatch() |
|
| 458 | |||
| 459 | /** |
||
| 460 | * @return boolean |
||
| 461 | */ |
||
| 462 | 6 | public function skipSuggestComposerRepositories() |
|
| 466 | |||
| 467 | /** |
||
| 468 | * @param $includeRootPackage |
||
| 469 | */ |
||
| 470 | public function setIncludeRootPackage($includeRootPackage) |
||
| 474 | |||
| 475 | /** |
||
| 476 | * @return bool |
||
| 477 | */ |
||
| 478 | 1 | public function getIncludeRootPackage() |
|
| 482 | } |
||
| 483 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.