| Conditions | 6 |
| Paths | 16 |
| Total Lines | 57 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 50 | public function renderReport(Report $report) |
||
| 51 | { |
||
| 52 | $writer = $this->getWriter(); |
||
| 53 | $writer->write('<checkstyle>'); |
||
| 54 | $writer->write(\PHP_EOL); |
||
| 55 | |||
| 56 | foreach ($report->getRuleViolations() as $violation) { |
||
| 57 | $fileName = $violation->getFileName(); |
||
| 58 | |||
| 59 | if ($this->fileName !== $fileName) { |
||
| 60 | // Not first file |
||
| 61 | if (null !== $this->fileName) { |
||
| 62 | $writer->write(' </file>' . \PHP_EOL); |
||
| 63 | } |
||
| 64 | // Store current file name |
||
| 65 | $this->fileName = $fileName; |
||
| 66 | |||
| 67 | $writer->write(' <file name="' . $fileName . '">' . \PHP_EOL); |
||
| 68 | } |
||
| 69 | |||
| 70 | $rule = $violation->getRule(); |
||
| 71 | |||
| 72 | $writer->write(' <error'); |
||
| 73 | $writer->write(' line="' . $violation->getBeginLine() . '"'); |
||
| 74 | $writer->write(' endline="' . $violation->getEndLine() . '"'); |
||
| 75 | $writer->write(\sprintf(' severity="%s"', $this->mapPriorityToSeverity($rule->getPriority()))); |
||
| 76 | $writer->write(\sprintf( |
||
| 77 | ' message="%s (%s, %s) "', |
||
| 78 | \htmlspecialchars($violation->getDescription()), |
||
| 79 | $rule->getName(), |
||
| 80 | $rule->getRuleSetName() |
||
| 81 | )); |
||
| 82 | |||
| 83 | $this->maybeAdd('package', $violation->getNamespaceName()); |
||
| 84 | $this->maybeAdd('externalInfoUrl', $rule->getExternalInfoUrl()); |
||
| 85 | $this->maybeAdd('function', $violation->getFunctionName()); |
||
| 86 | $this->maybeAdd('class', $violation->getClassName()); |
||
| 87 | $this->maybeAdd('method', $violation->getMethodName()); |
||
| 88 | //$this->_maybeAdd('variable', $violation->getVariableName()); |
||
| 89 | |||
| 90 | $writer->write(' />' . \PHP_EOL); |
||
| 91 | } |
||
| 92 | |||
| 93 | // Last file and at least one violation |
||
| 94 | if (null !== $this->fileName) { |
||
| 95 | $writer->write(' </file>' . \PHP_EOL); |
||
| 96 | } |
||
| 97 | |||
| 98 | foreach ($report->getErrors() as $error) { |
||
| 99 | $writer->write(' <file name="' . $error->getFile() . '">'); |
||
| 100 | $writer->write($error->getFile()); |
||
| 101 | $writer->write('<error msg="'); |
||
| 102 | $writer->write(\htmlspecialchars($error->getMessage())); |
||
| 103 | $writer->write(' severity="error" />' . \PHP_EOL); |
||
| 104 | } |
||
| 105 | |||
| 106 | $writer->write('</checkstyle>' . \PHP_EOL); |
||
| 107 | } |
||
| 123 | } |