| Conditions | 14 |
| Paths | 166 |
| Total Lines | 84 |
| Lines | 19 |
| Ratio | 22.62 % |
| Changes | 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 |
||
| 163 | protected function processReport($output) |
||
| 164 | { |
||
| 165 | $data = json_decode(trim($output), true); |
||
| 166 | |||
| 167 | if (!is_array($data)) { |
||
| 168 | $this->builder->log($output); |
||
| 169 | throw new \Exception('Could not process the report generated by PHP CS Fixer.'); |
||
| 170 | } |
||
| 171 | |||
| 172 | $warnings = 0; |
||
| 173 | |||
| 174 | foreach ($data['files'] as $item) { |
||
| 175 | $filename = $item['name']; |
||
| 176 | $appliedFixers = isset($item['appliedFixers']) ? $item['appliedFixers'] : []; |
||
| 177 | |||
| 178 | $parser = new Parser(); |
||
| 179 | $parsed = $parser->parse($item['diff']); |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @var \SebastianBergmann\Diff\Diff $diffItem |
||
| 183 | */ |
||
| 184 | $diffItem = $parsed[0]; |
||
| 185 | foreach ($diffItem->getChunks() as $chunk) { |
||
| 186 | $firstModifiedLine = $chunk->getStart(); |
||
| 187 | $foundChanges = false; |
||
| 188 | if (0 === $firstModifiedLine) { |
||
| 189 | $firstModifiedLine = null; |
||
| 190 | $foundChanges = true; |
||
| 191 | } |
||
| 192 | $chunkDiff = []; |
||
| 193 | foreach ($chunk->getLines() as $line) { |
||
| 194 | /** |
||
| 195 | * @var Line $line |
||
| 196 | */ |
||
| 197 | switch ($line->getType()) { |
||
| 198 | case Line::ADDED: |
||
| 199 | $symbol = '+'; |
||
| 200 | break; |
||
| 201 | case Line::REMOVED: |
||
| 202 | $symbol = '-'; |
||
| 203 | break; |
||
| 204 | default: |
||
| 205 | $symbol = ' '; |
||
| 206 | break; |
||
| 207 | } |
||
| 208 | $chunkDiff[] = $symbol . $line->getContent(); |
||
| 209 | if ($foundChanges) { |
||
| 210 | continue; |
||
| 211 | } |
||
| 212 | if (Line::UNCHANGED === $line->getType()) { |
||
| 213 | ++$firstModifiedLine; |
||
| 214 | continue; |
||
| 215 | } |
||
| 216 | |||
| 217 | $foundChanges = true; |
||
| 218 | } |
||
| 219 | |||
| 220 | $warnings++; |
||
| 221 | |||
| 222 | View Code Duplication | if ($this->reportErrors) { |
|
| 223 | $this->build->reportError( |
||
| 224 | $this->builder, |
||
| 225 | self::pluginName(), |
||
| 226 | "PHP CS Fixer suggestion:\r\n```diff\r\n" . implode("\r\n", $chunkDiff) . "\r\n```", |
||
| 227 | BuildError::SEVERITY_LOW, |
||
| 228 | $filename, |
||
| 229 | $firstModifiedLine |
||
| 230 | ); |
||
| 231 | } |
||
| 232 | } |
||
| 233 | |||
| 234 | View Code Duplication | if ($this->reportErrors && !empty($appliedFixers)) { |
|
| 235 | $this->build->reportError( |
||
| 236 | $this->builder, |
||
| 237 | self::pluginName(), |
||
| 238 | 'PHP CS Fixer failed fixers: ' . implode(', ', $appliedFixers), |
||
| 239 | BuildError::SEVERITY_LOW, |
||
| 240 | $filename |
||
| 241 | ); |
||
| 242 | } |
||
| 243 | } |
||
| 244 | |||
| 245 | return $warnings; |
||
| 246 | } |
||
| 247 | } |
||
| 248 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.