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