Conditions | 31 |
Paths | 640 |
Total Lines | 81 |
Code Lines | 57 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 992 |
Changes | 1 | ||
Bugs | 1 | Features | 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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
134 | 1 | $tblContent = []; |
|
135 | |||
136 | // Create a progress bar. |
||
137 | |||
138 | 1 | $steps = count($this->pkgResources); |
|
139 | 1 | $bar = $this->output->createProgressBar($steps); |
|
140 | |||
141 | // Initialize the status check procedure. |
||
142 | |||
143 | 1 | $this->line('Checking the resources installation ...'); |
|
144 | 1 | $bar->start(); |
|
145 | |||
146 | 1 | foreach ($this->pkgResources as $name => $resource) { |
|
147 | |||
148 | // Fill the status row of the current resource. |
||
149 | |||
150 | 1 | $tblContent[] = [ |
|
151 | 1 | $name, |
|
152 | 1 | $resource->description, |
|
153 | 1 | $this->getResourceStatus($resource), |
|
154 | 1 | var_export($resource->required, true), |
|
155 | ]; |
||
156 | |||
157 | // Advance the progress bar one step. |
||
158 | |||
159 | 1 | $bar->advance(); |
|
160 | } |
||
161 | |||
162 | // Finish the progress bar. |
||
163 | |||
164 | 1 | $bar->finish(); |
|
165 | 1 | $this->line(''); |
|
166 | 1 | $this->line('All resources checked succesfully!'); |
|
167 | |||
168 | // Return the rows. |
||
169 | |||
170 | 1 | return $tblContent; |
|
171 | } |
||
172 | |||
173 | /** |
||
174 | * Get the installation status of a package resource. |
||
175 | * |
||
176 | * @param PackageResource $resource The package resource to check |
||
177 | * @return string The resource status |
||
178 | */ |
||
179 | 1 | protected function getResourceStatus($resource) |
|
180 | { |
||
181 | 1 | $status = $this->status['uninstalled']; |
|
182 | |||
183 | 1 | if ($resource->installed()) { |
|
184 | 1 | $status = $this->status['installed']; |
|
185 | 1 | } elseif ($resource->exists()) { |
|
186 | 1 | $status = $this->status['mismatch']; |
|
187 | } |
||
188 | |||
189 | 1 | return $this->styleOutput($status['label'], $status['color']); |
|
190 | } |
||
191 | |||
192 | /** |
||
193 | * Display the legends of the possible status values. |
||
194 | * |
||
195 | * @return void |
||
196 | */ |
||
197 | 1 | protected function showStatusLegends() |
|
198 | { |
||
199 | 1 | $this->line('Status legends:'); |
|
200 | |||
201 | // Create the table headers for the legends. |
||
202 | |||
203 | $tblHeader = [ |
||
204 | 1 | $this->styleOutput('Status', 'cyan'), |
|
205 | 1 | $this->styleOutput('Description', 'cyan'), |
|
206 | ]; |
||
207 | |||
208 | // Create the table rows for the legends. |
||
209 | |||
210 | 1 | $tblContent = []; |
|
211 | |||
212 | 1 | foreach ($this->status as $status) { |
|
213 | 1 | $tblContent[] = [ |
|
214 | 1 | $this->styleOutput($status['label'], $status['color']), |
|
215 | 1 | $status['legend'], |
|
236 |