Complex classes like ModuleInstall 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 ModuleInstall, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | class ModuleInstall |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @const INSTALL_SCRIPT_VERSION : Script's version |
||
| 14 | */ |
||
| 15 | const INSTALL_SCRIPT_VERSION = '3.0.0'; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var string $projectPath : Path to root bfw project |
||
| 19 | */ |
||
| 20 | protected $projectPath = ''; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var string $bfwConfigPath : Path to bfw config directory |
||
| 24 | */ |
||
| 25 | protected $bfwConfigPath = ''; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var string $bfwModulePath : Path to bfw modules directory |
||
| 29 | */ |
||
| 30 | protected $bfwModulePath = ''; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var boolean $forceReinstall : Force complete reinstall of module |
||
| 34 | */ |
||
| 35 | protected $forceReinstall = false; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var string $name : Module name |
||
| 39 | */ |
||
| 40 | protected $name = ''; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var string $sourcePath : Path to module which be installed |
||
| 44 | */ |
||
| 45 | protected $sourcePath = ''; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var string $sourceSrcPath : Path to directory contains file to install |
||
| 49 | * in project module directory |
||
| 50 | */ |
||
| 51 | protected $sourceSrcPath = ''; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var string $sourceConfigPath : Path to directory contains config file |
||
| 55 | * to install in projet config directory |
||
| 56 | */ |
||
| 57 | protected $sourceConfigPath = ''; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var array $configFiles : List of config file |
||
| 61 | * to copy on the config directory |
||
| 62 | */ |
||
| 63 | protected $configFilesList = []; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var string|bool $sourceInstallScript : Script to run for a specific |
||
| 67 | * install of the module |
||
| 68 | */ |
||
| 69 | protected $sourceInstallScript = ''; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var string $targetSrcPath : Path to directory where module will be |
||
| 73 | * installed |
||
| 74 | */ |
||
| 75 | protected $targetSrcPath = ''; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @var string $targetConfigPath : Path to directory where config files |
||
| 79 | * will be installed |
||
| 80 | */ |
||
| 81 | protected $targetConfigPath = ''; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Constructor |
||
| 85 | * |
||
| 86 | * @param string $projectPath Path to root bfw project |
||
| 87 | * @param string $modulePath Path to module which be installed |
||
| 88 | */ |
||
| 89 | public function __construct($projectPath, $modulePath) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Get accessor to module name |
||
| 100 | * |
||
| 101 | * @return string : Module name |
||
| 102 | */ |
||
| 103 | public function getName() |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Find the module name and declare path to target directories install. |
||
| 110 | * |
||
| 111 | * @return void |
||
| 112 | */ |
||
| 113 | protected function findModuleName() |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Get infos for this module from BFW Module class |
||
| 124 | * It's a separate method for easy override. |
||
| 125 | * |
||
| 126 | * @return \stdClass |
||
| 127 | */ |
||
| 128 | protected function getInfosFromModule() |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Load module informations from files |
||
| 135 | * |
||
| 136 | * @return void |
||
| 137 | */ |
||
| 138 | public function loadInfos() |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Run module installation |
||
| 181 | * |
||
| 182 | * @param boolean $reinstall : If we force reinstall module |
||
| 183 | * |
||
| 184 | * @return void |
||
| 185 | */ |
||
| 186 | public function install($reinstall) |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Create symlink in bfw project module directory |
||
| 203 | * |
||
| 204 | * @return void |
||
| 205 | * |
||
| 206 | * @throws Exception : If remove symlink fail for reinstall option |
||
| 207 | */ |
||
| 208 | protected function createSymbolicLink() |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Create a directory in bfw project config directory for this module and |
||
| 245 | * copy all config files declared in this directory |
||
| 246 | * |
||
| 247 | * @return void |
||
| 248 | */ |
||
| 249 | protected function copyConfigFiles() |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Create a directory in bfw project config directory for this module |
||
| 285 | * |
||
| 286 | * @return boolean : If directory exist. |
||
| 287 | * |
||
| 288 | * @throws Exception : If remove directory fail for reinstall option |
||
| 289 | */ |
||
| 290 | protected function createConfigDirectory() |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Supprime les dossiers récursivement |
||
| 335 | * |
||
| 336 | * @param string $dirPath Le chemin vers le dossier |
||
| 337 | * |
||
| 338 | * @return boolean |
||
| 339 | */ |
||
| 340 | protected static function removeDirectory($dirPath) |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Copy a config file into config directory for this module |
||
| 374 | * |
||
| 375 | * @param string $configFileName : The config filename |
||
| 376 | * |
||
| 377 | * @return void |
||
| 378 | * |
||
| 379 | * @throws Exception If copy fail or if source file not exist |
||
| 380 | */ |
||
| 381 | protected function copyConfigFile($configFileName) |
||
| 409 | |||
| 410 | /** |
||
| 411 | * Run specific module install script if declared |
||
| 412 | * |
||
| 413 | * @return void |
||
| 414 | */ |
||
| 415 | protected function runInstallScript() |
||
| 441 | } |
||
| 442 |