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 |
||
80 | public function actionInit() |
||
81 | { |
||
82 | // username |
||
83 | $username = $this->getConfig('username'); |
||
84 | if (!$username) { |
||
85 | $username = $this->prompt('Whats your Github username?'); |
||
86 | $this->saveConfig('username', $username); |
||
87 | } |
||
88 | |||
89 | // clonetype |
||
90 | $cloneType = $this->getConfig('cloneType'); |
||
91 | if (!$cloneType) { |
||
92 | $cloneType = $this->select('Are you connected via ssh or https?', ['ssh' => 'ssh', 'http' => 'http']); |
||
93 | $this->saveConfig('cloneType', $cloneType); |
||
94 | } |
||
95 | |||
96 | $summary = []; |
||
97 | $itemWithoutFork = false; |
||
98 | |||
99 | // generate summary overview |
||
100 | foreach ($this->repos as $repo) { |
||
101 | $newRepoHome = $this->getFilesystemRepoPath($repo); |
||
102 | if (file_exists($newRepoHome . DIRECTORY_SEPARATOR . '.git')) { |
||
103 | $summary[] = $this->summaryItem($repo, false, true); |
||
104 | } elseif ($this->forkExists($username, $repo)) { |
||
105 | $summary[] = $this->summaryItem($repo, true, false); |
||
106 | } else { |
||
107 | $itemWithoutFork = true; |
||
108 | $summary[] = $this->summaryItem($repo, false, false); |
||
109 | } |
||
110 | } |
||
111 | |||
112 | if ($itemWithoutFork) { |
||
113 | Console::clearScreen(); |
||
114 | $this->outputInfo($this->markdown($this->text)); |
||
115 | foreach ($summary as $sum) { |
||
116 | if (!$sum[2] && !$sum[1]) { |
||
117 | $this->outputInfo($this->markdown("**{$sum[0]}**: https://github.com/luyadev/{$sum[0]}/fork", true)); |
||
118 | } |
||
119 | } |
||
120 | echo (new Table())->setHeaders(['Repo', 'Already initialized', 'Fork exists'])->setRows($summary)->run(); |
||
121 | $this->outputError("Repos without fork detected. Those repos will be initialized as READ ONLY. It means you can not push any changes to them."); |
||
122 | |||
123 | if (!$this->confirm("Continue?")) { |
||
|
|||
124 | return $this->outputError('Abort by User.'); |
||
125 | } |
||
126 | } |
||
127 | |||
128 | // foreach summary and clone |
||
129 | foreach ($summary as $sum) { |
||
130 | $repo = $sum[0]; |
||
131 | $hasFork = $sum[2]; |
||
132 | $exists = $sum[1]; |
||
133 | |||
134 | // continue already initialized repos. |
||
135 | if ($exists) { |
||
136 | continue; |
||
137 | } |
||
138 | |||
139 | $newRepoHome = $this->getFilesystemRepoPath($repo); |
||
140 | |||
141 | if ($hasFork) { |
||
142 | $cloneUrl = ($cloneType == 'ssh') ? "[email protected]:{$username}/{$repo}.git" : "https://github.com/{$username}/{$repo}.git"; |
||
143 | } else { |
||
144 | $cloneUrl = ($cloneType == 'ssh') ? "[email protected]:luyadev/{$repo}.git" : "https://github.com/{$username}/{$repo}.git"; |
||
145 | } |
||
146 | |||
147 | $this->cloneRepo($repo, $cloneUrl, $newRepoHome); |
||
148 | } |
||
149 | |||
150 | return $this->outputSuccess("init complete."); |
||
151 | } |
||
152 | |||
177 |
If an expression can have both
false
, andnull
as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.