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