| Conditions | 15 |
| Paths | 53 |
| Total Lines | 45 |
| Code Lines | 32 |
| 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 |
||
| 132 | protected static function printCheckLastReports(object $response, bool $verbose, int $maxReportsNumber) |
||
| 133 | { |
||
| 134 | // print last reports |
||
| 135 | if ($verbose){ |
||
| 136 | $nbLastReports = isset($response->data->reports) ? count($response->data->reports) : 0; |
||
| 137 | |||
| 138 | if ($nbLastReports > 0){ |
||
| 139 | Console::log(' Last reports:', 'white'); |
||
| 140 | $numberDiplayedReports = 0; |
||
| 141 | $defaultColor = 'lightyellow'; // reset color for last reports |
||
| 142 | |||
| 143 | foreach ($response->data->reports as $lastReport){ |
||
| 144 | $categories = []; |
||
| 145 | foreach (array_filter($lastReport->categories) as $catId){ |
||
| 146 | $cat = ApiHandler::getCategoryNamebyId($catId)[0]; |
||
| 147 | if ($cat !== false) { |
||
| 148 | $categories[] = $cat; |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | $line = Console::text(' →', $defaultColor); |
||
| 153 | $line .= self::printResult(' reported at: ', self::getDate($lastReport->reportedAt), $defaultColor, '', false); |
||
| 154 | // $line .= self::printResult(' by user: ', $lastReport->reporterId, $defaultColor, '', false); |
||
| 155 | if (isset($lastReport->reporterCountryCode) && isset($lastReport->reporterCountryName)){ |
||
| 156 | $line .= Console::text(' from: ', 'white'); |
||
| 157 | $line .= self::printResult('', $lastReport->reporterCountryCode, $defaultColor, '', false); |
||
| 158 | $line .= Console::text(' - ', 'white'); |
||
| 159 | $line .= self::printResult('', $lastReport->reporterCountryName, $defaultColor, '', false); |
||
| 160 | } |
||
| 161 | $line .= Console::text(' with categor' . (count($categories) > 1 ? "ies: " : "y: "), 'white'); |
||
| 162 | foreach ($categories as $key => $cat) { |
||
| 163 | $line .= Console::text($key==0 ? '' : ',' , 'white') . Console::text($cat, $defaultColor); |
||
| 164 | } |
||
| 165 | Console::log($line); |
||
| 166 | |||
| 167 | // counter |
||
| 168 | $numberDiplayedReports++; |
||
| 169 | if ($numberDiplayedReports === $maxReportsNumber || $numberDiplayedReports === $nbLastReports) { |
||
| 170 | $line = Console::text(' (', 'white'); |
||
| 171 | $line .= Console::text($numberDiplayedReports, $defaultColor); |
||
| 172 | $line .= Console::text('/', 'white'); |
||
| 173 | $line .= Console::text($nbLastReports, $defaultColor); |
||
| 174 | $line .= Console::text($numberDiplayedReports > 1 ? ' reports displayed)': ' report displayed)', 'white'); |
||
| 175 | Console::log($line); |
||
| 176 | break; |
||
| 177 | } |
||
| 182 | } |