| Conditions | 7 |
| Paths | 34 |
| Total Lines | 71 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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:
| 1 | <?php |
||
| 112 | protected function writeStatus($done, $total, $size = 30, $lineWidth = -1) |
||
| 113 | { |
||
| 114 | if ($lineWidth <= 0) { |
||
| 115 | $lineWidth = input()->env('COLUMNS'); |
||
| 116 | } |
||
| 117 | |||
| 118 | static $start_time; |
||
| 119 | |||
| 120 | // to take account for [ and ] |
||
| 121 | $size -= 3; |
||
| 122 | // if we go over our bound, just ignore it |
||
| 123 | if ($done > $total) { |
||
| 124 | return; |
||
| 125 | } |
||
| 126 | |||
| 127 | if (empty($start_time)) { |
||
| 128 | $start_time = time(); |
||
| 129 | } |
||
| 130 | $now = time(); |
||
| 131 | |||
| 132 | $percent = (double)($done / $total); |
||
| 133 | |||
| 134 | $bar = floor($percent * $size); |
||
| 135 | |||
| 136 | // jump to the begining |
||
| 137 | output()->write("\r"); |
||
| 138 | |||
| 139 | // jump a line up |
||
| 140 | output()->write("\x1b[A"); |
||
| 141 | |||
| 142 | $statusBar = "["; |
||
| 143 | $statusBar .= str_repeat("=", $bar); |
||
| 144 | if ($bar < $size) { |
||
| 145 | $statusBar .= ">"; |
||
| 146 | $statusBar .= str_repeat(" ", $size - $bar); |
||
| 147 | } else { |
||
| 148 | $statusBar .= "="; |
||
| 149 | } |
||
| 150 | |||
| 151 | $percentOutput = number_format($percent * 100, 0); |
||
| 152 | |||
| 153 | $statusBar .= "]"; |
||
| 154 | $details = "$percentOutput% $done/$total"; |
||
| 155 | |||
| 156 | $rate = ($now - $start_time) / $done; |
||
| 157 | $left = $total - $done; |
||
| 158 | $eta = round($rate * $left, 2); |
||
| 159 | |||
| 160 | $elapsed = $now - $start_time; |
||
| 161 | |||
| 162 | |||
| 163 | $details .= ' ' . language()->getLine('CLI_PROGRESS_BAR_ESTIMATION') . ': ' . $this->formatTime($eta) . ' ' . language()->getLine('CLI_PROGRESS_BAR_ELAPSED') . ': ' . $this->formatTime($elapsed) . ' '; |
||
| 164 | |||
| 165 | $lineWidth--; |
||
| 166 | if (strlen($details) >= $lineWidth) { |
||
| 167 | $details = substr($details, 0, $lineWidth - 1); |
||
| 168 | } |
||
| 169 | |||
| 170 | output()->write(implode(PHP_EOL, [ |
||
| 171 | $details, |
||
| 172 | $statusBar, |
||
| 173 | ])); |
||
| 174 | |||
| 175 | //echo "$details\n$status_bar"; |
||
| 176 | |||
| 177 | flush(); |
||
| 178 | |||
| 179 | // when done, send a newline |
||
| 180 | if ($done == $total) { |
||
| 181 | //echo "\n"; |
||
| 182 | output()->write(PHP_EOL); |
||
| 183 | } |
||
| 229 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.