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) |
||
227 | |||
228 | /** |
||
229 | * Remove a given repo from filesystem. |
||
230 | * |
||
231 | * @param string $repo The repo name like `luya-module-cms` without vendor. |
||
232 | */ |
||
233 | public function actionRemove($repo) |
||
244 | |||
245 | /** |
||
246 | * |
||
247 | * @return \Nadar\PhpComposerReader\ComposerReader |
||
248 | */ |
||
249 | protected function getProjectComposerReader() |
||
253 | |||
254 | private $_gitWrapper; |
||
255 | |||
256 | /** |
||
257 | * @return \GitWrapper\GitWrapper |
||
258 | */ |
||
259 | protected function getGitWrapper() |
||
268 | |||
269 | /** |
||
270 | * |
||
271 | * @param string $repo |
||
272 | * @param string $isFork |
||
273 | * @param string $exists |
||
274 | * @return array |
||
275 | */ |
||
276 | private function summaryItem($repo, $isFork, $exists) |
||
280 | |||
281 | /** |
||
282 | * |
||
283 | * @param string $repo |
||
284 | * @return string |
||
285 | */ |
||
286 | private function getFilesystemRepoPath($repo) |
||
290 | |||
291 | /** |
||
292 | * |
||
293 | * @param string $username |
||
294 | * @param string $repo |
||
295 | * @return boolean |
||
296 | */ |
||
297 | private function forkExists($username, $repo) |
||
301 | |||
302 | /** |
||
303 | * |
||
304 | * @param string $text |
||
305 | * @param boolean $paragraph |
||
306 | * @return string |
||
307 | */ |
||
308 | private function markdown($text, $paragraph = false) |
||
318 | |||
319 | /** |
||
320 | * Return the url to clone based on config clone type (ssh/https). |
||
321 | * |
||
322 | * @param string $repo |
||
323 | * @param string $username |
||
324 | * @return string |
||
325 | */ |
||
326 | private function getCloneUrlBasedOnType($repo, $username) |
||
330 | |||
331 | /** |
||
332 | * Rebase existing repo. |
||
333 | * |
||
334 | * @param string $repo |
||
335 | * @param string $repoFileSystemPath |
||
336 | */ |
||
337 | private function rebaseRepo($repo, $repoFileSystemPath) |
||
356 | |||
357 | /** |
||
358 | * Clone a repo into the repos folder. |
||
359 | * |
||
360 | * @param string $repo |
||
361 | * @param string $cloneUrl |
||
362 | * @param string $newRepoHome |
||
363 | * @param string $upstreamUsername The upstream vendor name of the repo if available. |
||
364 | */ |
||
365 | private function cloneRepo($repo, $cloneUrl, $newRepoHome, $upstreamUsername) |
||
377 | } |
||
378 |
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: