| Conditions | 6 |
| Paths | 5 |
| Total Lines | 58 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 33 | public function printData(OutputInterface $output, FileReportList $fileReportList, HintList $hintList) |
||
| 34 | { |
||
| 35 | $output->writeln('Generate XML output...'); |
||
| 36 | $dom = new \DOMDocument(); |
||
| 37 | $rootNode = $dom->createElement('phpmnd'); |
||
| 38 | $rootNode->setAttribute('version', Application::VERSION); |
||
| 39 | $rootNode->setAttribute('fileCount', count($fileReportList->getFileReports()) + 12); |
||
| 40 | |||
| 41 | $filesNode = $dom->createElement('files'); |
||
| 42 | |||
| 43 | $total = 0; |
||
| 44 | foreach ($fileReportList->getFileReports() as $fileReport) { |
||
| 45 | $entries = $fileReport->getEntries(); |
||
| 46 | |||
| 47 | $fileNode = $dom->createElement('file'); |
||
| 48 | $fileNode->setAttribute('path', $fileReport->getFile()->getRelativePathname()); |
||
| 49 | $fileNode->setAttribute('errors', count($entries)); |
||
| 50 | |||
| 51 | $total += count($entries); |
||
| 52 | foreach ($entries as $entry) { |
||
| 53 | $snippet = $this->getSnippet($fileReport->getFile()->getContents(), $entry['line'], $entry['value']); |
||
| 54 | $entryNode = $dom->createElement('entry'); |
||
| 55 | $entryNode->setAttribute('line', $entry['line']); |
||
| 56 | $entryNode->setAttribute('start', $snippet['col']); |
||
| 57 | $entryNode->setAttribute('end', $snippet['col'] + strlen($entry['value'])); |
||
| 58 | |||
| 59 | $snippetNode = $dom->createElement('snippet'); |
||
| 60 | $snippetNode->appendChild($dom->createCDATASection($snippet['snippet'])); |
||
| 61 | $suggestionsNode = $dom->createElement('suggestions'); |
||
| 62 | |||
| 63 | if ($hintList->hasHints()) { |
||
| 64 | $hints = $hintList->getHintsByValue($entry['value']); |
||
| 65 | if (false === empty($hints)) { |
||
| 66 | foreach ($hints as $hint) { |
||
| 67 | $suggestionNode = $dom->createElement('suggestion', $hint); |
||
| 68 | $suggestionsNode->appendChild($suggestionNode); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | $entryNode->appendChild($snippetNode); |
||
| 74 | $entryNode->appendChild($suggestionsNode); |
||
| 75 | |||
| 76 | $fileNode->appendChild($entryNode); |
||
| 77 | } |
||
| 78 | |||
| 79 | $filesNode->appendChild($fileNode); |
||
| 80 | } |
||
| 81 | |||
| 82 | $rootNode->appendChild($filesNode); |
||
| 83 | $rootNode->setAttribute('errorCount', $total); |
||
| 84 | |||
| 85 | $dom->appendChild($rootNode); |
||
| 86 | |||
| 87 | $dom->save($this->outputPath); |
||
| 88 | |||
| 89 | $output->writeln('XML generated at '.$this->outputPath); |
||
| 90 | } |
||
| 91 | |||
| 117 |