Conditions | 10 |
Paths | 25 |
Total Lines | 51 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Tests | 35 |
CRAP Score | 10.0021 |
Changes | 7 | ||
Bugs | 2 | Features | 3 |
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 |
||
205 | 7 | public function write() { |
|
206 | // Determine the width of the last column. |
||
207 | 7 | $columnWidths = array_sum($this->columnWidths); |
|
208 | 7 | $totalWidth = $this->indent + $columnWidths + $this->padding * (count($this->columnWidths) - 1); |
|
209 | |||
210 | 7 | $lastWidth = end($this->columnWidths) + $this->maxWidth - $totalWidth; |
|
211 | 7 | $lastWidth = max($lastWidth, 10); // min width of 10 |
|
212 | 7 | $this->columnWidths[count($this->columnWidths) - 1] = $lastWidth; |
|
213 | |||
214 | // Loop through each row and write it. |
||
215 | 7 | foreach ($this->rows as $row) { |
|
216 | 7 | $rowLines = []; |
|
1 ignored issue
–
show
|
|||
217 | 7 | $lineCount = 0; |
|
218 | |||
219 | // Split the cells into lines. |
||
220 | 7 | foreach ($row as $i => $cell) { |
|
221 | 7 | list($text,) = $cell; |
|
222 | 7 | $width = $this->columnWidths[$i]; |
|
223 | |||
224 | 7 | $lines = Cli::breakLines($text, $width, $i < count($this->columnWidths) - 1); |
|
225 | 7 | $rowLines[] = $lines; |
|
226 | 7 | $lineCount = max($lineCount, count($lines)); |
|
1 ignored issue
–
show
|
|||
227 | 7 | } |
|
228 | |||
229 | // Write all of the lines. |
||
230 | 7 | for ($i = 0; $i < $lineCount; $i++) { |
|
231 | 7 | foreach ($rowLines as $j => $lines) { |
|
232 | 7 | $padding = $j === 0 ? $this->indent : $this->padding; |
|
233 | |||
234 | 7 | if (isset($lines[$i])) { |
|
235 | 7 | if ($this->formatOutput) { |
|
236 | 3 | if(isset($row[$j])) { |
|
237 | 3 | $wrap = $row[$j][1]; |
|
238 | 3 | } else { |
|
239 | // if we're out of array, use the latest wraps |
||
240 | $wrap = $row[count($row)-1][1]; |
||
241 | } |
||
242 | |||
243 | 3 | echo str_repeat(' ', $padding).$wrap[0].$lines[$i].$wrap[1]; |
|
244 | 3 | } else { |
|
245 | 4 | echo str_repeat(' ', $padding).$lines[$i]; |
|
246 | } |
||
247 | 7 | } elseif ($j < count($this->columnWidths) - 1) { |
|
248 | // This is an empty line. Write the spaces. |
||
249 | 2 | echo str_repeat(' ', $padding + $this->columnWidths[$j]); |
|
250 | 2 | } |
|
251 | 7 | } |
|
252 | 7 | echo PHP_EOL; |
|
253 | 7 | } |
|
254 | 7 | } |
|
255 | 7 | } |
|
256 | } |
||
257 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.