Complex classes like UpgradeControl 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 UpgradeControl, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 3 | class UpgradeControl |
||
| 4 | { |
||
| 5 | /** @var PatchStatus[] */ |
||
| 6 | public $upgradeQueue = array(); |
||
| 7 | |||
| 8 | /** @var string[] */ |
||
| 9 | public $needWriteFiles = array(); |
||
| 10 | |||
| 11 | /** @var bool */ |
||
| 12 | public $needUpgrade = false; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var array support sites pulled from language files -- support.php |
||
| 16 | */ |
||
| 17 | public $supportSites = array(); |
||
| 18 | |||
| 19 | /** @var bool */ |
||
| 20 | public $needMainfileRewrite = false; |
||
| 21 | |||
| 22 | /** @var string[] */ |
||
| 23 | public $mainfileKeys = array(); |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var string language being used in the upgrade process |
||
| 27 | */ |
||
| 28 | public $upgradeLanguage; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * get a list of directories inside a directory |
||
| 32 | * |
||
| 33 | * @param string $dirname directory to search |
||
| 34 | * |
||
| 35 | * @return string[] |
||
| 36 | */ |
||
| 37 | public function getDirList($dirname) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @return string[] |
||
| 58 | */ |
||
| 59 | public function availableLanguages() |
||
| 64 | |||
| 65 | |||
| 66 | public function loadLanguage($domain, $language = null) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Determine the language to use. |
||
| 85 | * - Xoops configuration |
||
| 86 | * - stored cookie |
||
| 87 | * - lang parameter passed to script |
||
| 88 | * Save the result in a cookie |
||
| 89 | * |
||
| 90 | * @return string the language to use in the upgrade process |
||
| 91 | */ |
||
| 92 | public function determineLanguage() |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Examine upgrade directories and determine: |
||
| 113 | * - which tasks need to run |
||
| 114 | * - which files need to be writable |
||
| 115 | * |
||
| 116 | * @return bool true of upgrade is needed |
||
| 117 | */ |
||
| 118 | public function buildUpgradeQueue() |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Get count of patch sets that need to be applied. |
||
| 159 | * |
||
| 160 | * @return int count of patch sets to apply |
||
| 161 | */ |
||
| 162 | public function countUpgradeQueue() |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @return string next unapplied patch directory |
||
| 176 | */ |
||
| 177 | public function getNextPatch() |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Return form consisting of a single button. |
||
| 195 | * |
||
| 196 | * @param string $action URL for form action |
||
| 197 | * @param array|null $parameters array of parameters |
||
| 198 | * |
||
| 199 | * @return string |
||
| 200 | */ |
||
| 201 | public function oneButtonContinueForm($action = 'index.php', $parameters = array('action' =>'next')) |
||
| 213 | |||
| 214 | public function storeMainfileCheck($needMainfileRewrite, $mainfileKeys) |
||
| 222 | |||
| 223 | } |
||
| 224 |
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state