Complex classes like DefaultGoal 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 DefaultGoal, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | class DefaultGoal extends BaseGoal |
||
| 21 | { |
||
| 22 | public $goalName; |
||
| 23 | |||
| 24 | public $done = []; |
||
| 25 | |||
| 26 | protected $_fileType = null; |
||
| 27 | |||
| 28 | public function getFileType() |
||
| 32 | |||
| 33 | public function setFileType($type) |
||
| 37 | |||
| 38 | public function setDeps($deps) |
||
| 46 | |||
| 47 | public function getDeps() |
||
| 51 | |||
| 52 | public function actionDeps() |
||
| 65 | |||
| 66 | public function runRequest($request) |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Runs array of requests. Stops on failure and returns exit code. |
||
| 73 | * @param null|string|array $requests |
||
| 74 | */ |
||
| 75 | public function runRequests($requests) |
||
| 91 | |||
| 92 | public function isDone($action, $timestamp = null) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Mark action as already done. |
||
| 105 | * |
||
| 106 | * @param string $action action id |
||
| 107 | * @param int $time microtime when action was done, false for action was not done |
||
| 108 | */ |
||
| 109 | public function markDone($action, $time = null) |
||
| 113 | |||
| 114 | public function actionPerform($name = null, $path = null) |
||
| 119 | |||
| 120 | public function actionLoad() |
||
| 124 | |||
| 125 | public function actionSave() |
||
| 129 | |||
| 130 | public function actionMake() |
||
| 134 | |||
| 135 | public function runAction($id, $params = []) |
||
| 145 | |||
| 146 | public function runActions($actions) |
||
| 157 | |||
| 158 | public static function isNotOk($res) |
||
| 162 | |||
| 163 | public function options($actionId) |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Runs given binary with given arguments. |
||
| 170 | * @param string $name |
||
| 171 | * @param string $args |
||
| 172 | * @return int exit code |
||
| 173 | */ |
||
| 174 | public function passthru($name, $args = '') |
||
| 178 | |||
| 179 | public function getRobo() |
||
| 183 | |||
| 184 | public function getConfig() |
||
| 188 | |||
| 189 | public function getPackage() |
||
| 193 | |||
| 194 | public function getVendor() |
||
| 198 | |||
| 199 | public function getVcs() |
||
| 204 | } |
||
| 205 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.