Complex classes like RepoController 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 RepoController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 42 | class RepoController extends BaseDevCommand |
||
| 43 | { |
||
| 44 | const CONFIG_VAR_USERNAME = 'username'; |
||
| 45 | |||
| 46 | const CONFIG_VAR_CLONETYPE = 'cloneType'; |
||
| 47 | |||
| 48 | const CONFIG_VAR_CUSTOMCLONES = 'customClones'; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var string Default action is actionInit(); |
||
| 52 | */ |
||
| 53 | public $defaultAction = 'init'; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var array The default repos from luyadev |
||
| 57 | */ |
||
| 58 | public $repos = [ |
||
| 59 | 'luya', |
||
| 60 | 'luya-module-admin', |
||
| 61 | 'luya-module-cms', |
||
| 62 | ]; |
||
| 63 | |||
| 64 | public $text = <<<EOT |
||
| 65 | **CLONE REPOS** |
||
| 66 | |||
| 67 | We've detected that you don't have all module repos forked to your account. You can only push changes to the forked repos, all others are **READ ONLY**. |
||
| 68 | |||
| 69 | If you want to work on a specific repo, make sure that repo is forked to your Github account. |
||
| 70 | |||
| 71 | You can also skip this command, fork the repos and rerun this command again. |
||
| 72 | |||
| 73 | **FORK ME** |
||
| 74 | EOT; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Initilize the main repos. |
||
| 78 | * |
||
| 79 | * @return number |
||
| 80 | */ |
||
| 81 | public function actionInit() |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Update all repos to master branch from upstream. |
||
| 156 | */ |
||
| 157 | public function actionUpdate() |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Clone a repo into the repos folder. |
||
| 170 | * |
||
| 171 | * @param string $repo |
||
| 172 | * @param string $vendor |
||
| 173 | */ |
||
| 174 | public function actionClone($vendor = null, $repo = null) |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Remove a given repo from filesystem. |
||
| 227 | * |
||
| 228 | * @param string $repo The repo name like `luya-module-cms` without vendor. |
||
| 229 | */ |
||
| 230 | public function actionRemove($repo) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * |
||
| 244 | * @return \Nadar\PhpComposerReader\ComposerReader |
||
| 245 | */ |
||
| 246 | protected function getProjectComposerReader() |
||
| 250 | |||
| 251 | private $_gitWrapper; |
||
| 252 | |||
| 253 | /** |
||
| 254 | * @return \GitWrapper\GitWrapper |
||
| 255 | */ |
||
| 256 | protected function getGitWrapper() |
||
| 265 | |||
| 266 | /** |
||
| 267 | * |
||
| 268 | * @param string $repo |
||
| 269 | * @param string $isFork |
||
| 270 | * @param string $exists |
||
| 271 | * @return array |
||
| 272 | */ |
||
| 273 | private function summaryItem($repo, $isFork, $exists) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * |
||
| 280 | * @param string $repo |
||
| 281 | * @return string |
||
| 282 | */ |
||
| 283 | private function getFilesystemRepoPath($repo) |
||
| 287 | |||
| 288 | /** |
||
| 289 | * |
||
| 290 | * @param string $username |
||
| 291 | * @param string $repo |
||
| 292 | * @return boolean |
||
| 293 | */ |
||
| 294 | private function forkExists($username, $repo) |
||
| 298 | |||
| 299 | /** |
||
| 300 | * |
||
| 301 | * @param string $text |
||
| 302 | * @param boolean $paragraph |
||
| 303 | * @return string |
||
| 304 | */ |
||
| 305 | private function markdown($text, $paragraph = false) |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Return the url to clone based on config clone type (ssh/https). |
||
| 318 | * |
||
| 319 | * @param string $repo |
||
| 320 | * @param string $username |
||
| 321 | * @return string |
||
| 322 | */ |
||
| 323 | private function getCloneUrlBasedOnType($repo, $username) |
||
| 327 | |||
| 328 | /** |
||
| 329 | * Rebase existing repo. |
||
| 330 | * |
||
| 331 | * @param string $repo |
||
| 332 | * @param string $repoFileSystemPath |
||
| 333 | */ |
||
| 334 | private function rebaseRepo($repo, $repoFileSystemPath) |
||
| 347 | |||
| 348 | /** |
||
| 349 | * Clone a repo into the repos folder. |
||
| 350 | * |
||
| 351 | * @param string $repo |
||
| 352 | * @param string $cloneUrl |
||
| 353 | * @param string $newRepoHome |
||
| 354 | * @param string $upstreamUsername The upstream vendor name of the repo if available. |
||
| 355 | */ |
||
| 356 | private function cloneRepo($repo, $cloneUrl, $newRepoHome, $upstreamUsername) |
||
| 368 | } |
||
| 369 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: