| Conditions | 16 |
| Paths | 208 |
| Total Lines | 72 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 69 | public function actionInit() |
||
| 70 | { |
||
| 71 | // username |
||
| 72 | $username = $this->getConfig(self::CONFIG_VAR_USERNAME); |
||
| 73 | if (!$username) { |
||
| 74 | $username = $this->prompt('Whats your Github username?'); |
||
| 75 | $this->saveConfig(self::CONFIG_VAR_USERNAME, $username); |
||
| 76 | } |
||
| 77 | |||
| 78 | // clonetype |
||
| 79 | $cloneType = $this->getConfig(self::CONFIG_VAR_CLONETYPE); |
||
| 80 | if (!$cloneType) { |
||
| 81 | $cloneType = $this->select('Are you connected via ssh or https?', ['ssh' => 'ssh', 'http' => 'http']); |
||
| 82 | $this->saveConfig(self::CONFIG_VAR_CLONETYPE, $cloneType); |
||
| 83 | } |
||
| 84 | |||
| 85 | $summary = []; |
||
| 86 | $itemWithoutFork = false; |
||
| 87 | |||
| 88 | // generate summary overview |
||
| 89 | foreach ($this->repos as $repo) { |
||
| 90 | $newRepoHome = $this->getFilesystemRepoPath($repo); |
||
| 91 | if (file_exists($newRepoHome . DIRECTORY_SEPARATOR . '.git')) { |
||
| 92 | $summary[] = $this->summaryItem($repo, false, true); |
||
| 93 | } elseif ($this->forkExists($username, $repo)) { |
||
| 94 | $summary[] = $this->summaryItem($repo, true, false); |
||
| 95 | } else { |
||
| 96 | $itemWithoutFork = true; |
||
| 97 | $summary[] = $this->summaryItem($repo, false, false); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | if ($itemWithoutFork) { |
||
| 102 | Console::clearScreen(); |
||
| 103 | $this->outputInfo($this->markdown($this->text)); |
||
| 104 | foreach ($summary as $sum) { |
||
| 105 | if (!$sum[2] && !$sum[1]) { |
||
| 106 | $this->outputInfo($this->markdown("**{$sum[0]}**: https://github.com/luyadev/{$sum[0]}/fork", true)); |
||
| 107 | } |
||
| 108 | } |
||
| 109 | echo (new Table())->setHeaders(['Repo', 'Already initialized', 'Fork exists'])->setRows($summary)->run(); |
||
| 110 | $this->outputError("Repos without fork detected. Those repos will be initialized as READ ONLY. It means you can not push any changes to them."); |
||
| 111 | |||
| 112 | if (!$this->confirm("Continue?")) { |
||
|
|
|||
| 113 | return $this->outputError('Abort by User.'); |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | // foreach summary and clone |
||
| 118 | foreach ($summary as $sum) { |
||
| 119 | $repo = $sum[0]; |
||
| 120 | $hasFork = $sum[2]; |
||
| 121 | $exists = $sum[1]; |
||
| 122 | |||
| 123 | // continue already initialized repos. |
||
| 124 | if ($exists) { |
||
| 125 | continue; |
||
| 126 | } |
||
| 127 | |||
| 128 | $newRepoHome = $this->getFilesystemRepoPath($repo); |
||
| 129 | |||
| 130 | if ($hasFork) { |
||
| 131 | $cloneUrl = ($cloneType == 'ssh') ? "[email protected]:{$username}/{$repo}.git" : "https://github.com/{$username}/{$repo}.git"; |
||
| 132 | } else { |
||
| 133 | $cloneUrl = ($cloneType == 'ssh') ? "[email protected]:luyadev/{$repo}.git" : "https://github.com/{$username}/{$repo}.git"; |
||
| 134 | } |
||
| 135 | |||
| 136 | $this->cloneRepo($repo, $cloneUrl, $newRepoHome, 'luyadev'); |
||
| 137 | } |
||
| 138 | |||
| 139 | return $this->outputSuccess("init complete."); |
||
| 140 | } |
||
| 141 | |||
| 252 |
If an expression can have both
false, andnullas possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.