| Conditions | 10 | 
| Paths | 29 | 
| Total Lines | 93 | 
| Code Lines | 65 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 3 | ||
| Bugs | 1 | 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  | 
            ||
| 18 | public function outputResults(AnalysisResults $analysisResults): string  | 
            ||
| 19 |     { | 
            ||
| 20 |         if (!extension_loaded('simplexml')) { | 
            ||
| 21 |             throw new SarbException('Simple XML required for JUnit output format'); // @codeCoverageIgnore | 
            ||
| 22 | }  | 
            ||
| 23 | |||
| 24 |         if (0 === $analysisResults->getCount()) { | 
            ||
| 25 | return <<<XML  | 
            ||
| 26 | <?xml version="1.0" encoding="UTF-8"?>  | 
            ||
| 27 | <testsuites  | 
            ||
| 28 | name="SARB" tests="1" failures="0">  | 
            ||
| 29 | <testsuite errors="0" tests="1" failures="0" name="Success">  | 
            ||
| 30 | <testcase name="Success"/>  | 
            ||
| 31 | </testsuite>  | 
            ||
| 32 | </testsuites>  | 
            ||
| 33 | |||
| 34 | XML;  | 
            ||
| 35 | }  | 
            ||
| 36 | |||
| 37 | $xml = $this->getXmlString($analysisResults->getCount());  | 
            ||
| 38 | $test = new SimpleXMLElement($xml);  | 
            ||
| 39 | |||
| 40 | $suitCount = 0;  | 
            ||
| 41 | $caseCount = 0;  | 
            ||
| 42 | $previousRelativeFileName = null;  | 
            ||
| 43 | $testsuite = null;  | 
            ||
| 44 |         foreach ($analysisResults->getAnalysisResults() as $analysisResult) { | 
            ||
| 45 | $details = $analysisResult->getFullDetails();  | 
            ||
| 46 | |||
| 47 | /** @var mixed $type */  | 
            ||
| 48 | $type = $details['type'] ?? null;  | 
            ||
| 49 |             if (!is_string($type)) { | 
            ||
| 50 | $type = 'error';  | 
            ||
| 51 | }  | 
            ||
| 52 | $type = strtolower($type);  | 
            ||
| 53 | |||
| 54 | /** @var mixed $column */  | 
            ||
| 55 | $column = $details['column'] ?? null;  | 
            ||
| 56 |             if (is_numeric($column)) { | 
            ||
| 57 | $column = (string) ((int) $column);  | 
            ||
| 58 |             } else { | 
            ||
| 59 | $column = '0';  | 
            ||
| 60 | }  | 
            ||
| 61 | |||
| 62 | $relativeFileName = $analysisResult->getLocation()->getRelativeFileName()->getFileName();  | 
            ||
| 63 | |||
| 64 |             if ((null === $testsuite) || ($previousRelativeFileName !== $relativeFileName)) { | 
            ||
| 65 | // Add final counts to previous testsuite (if one exists)  | 
            ||
| 66 | $this->addCounts($testsuite, $caseCount);  | 
            ||
| 67 | |||
| 68 |                 $testsuite = $test->addChild('testsuite'); | 
            ||
| 69 |                 $testsuite->addAttribute('name', $relativeFileName); | 
            ||
| 70 | |||
| 71 | $previousRelativeFileName = $relativeFileName;  | 
            ||
| 72 | ++$suitCount;  | 
            ||
| 73 | $caseCount = 0;  | 
            ||
| 74 | }  | 
            ||
| 75 | |||
| 76 | $lineSprint = sprintf(  | 
            ||
| 77 | '%s at %s (%d:%s)',  | 
            ||
| 78 | $analysisResult->getType()->getType(),  | 
            ||
| 79 | $analysisResult->getLocation()->getAbsoluteFileName()->getFileName(),  | 
            ||
| 80 | $analysisResult->getLocation()->getLineNumber()->getLineNumber(),  | 
            ||
| 81 | $column  | 
            ||
| 82 | );  | 
            ||
| 83 |             $testcase = $testsuite->addChild('testcase'); | 
            ||
| 84 |             $testcase->addAttribute('name', $lineSprint); | 
            ||
| 85 |             $failure = $testcase->addChild('failure'); | 
            ||
| 86 |             $failure->addAttribute('type', $type); | 
            ||
| 87 | $failure->addAttribute(  | 
            ||
| 88 | 'message',  | 
            ||
| 89 | $analysisResult->getMessage()  | 
            ||
| 90 | );  | 
            ||
| 91 | ++$caseCount;  | 
            ||
| 92 | }  | 
            ||
| 93 | |||
| 94 | $this->addCounts($testsuite, $caseCount);  | 
            ||
| 95 | |||
| 96 |         $dom = new DOMDocument('1.0'); | 
            ||
| 97 | $dom->preserveWhiteSpace = false;  | 
            ||
| 98 | $dom->formatOutput = true;  | 
            ||
| 99 | $asXml = $test->asXML();  | 
            ||
| 100 | |||
| 101 |         if (false !== $asXml) { | 
            ||
| 102 | $dom->loadXML($asXml);  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 103 |         } else { | 
            ||
| 104 |             throw new SarbException('xml could not be loaded'); // @codeCoverageIgnore | 
            ||
| 105 | }  | 
            ||
| 106 | $saveXml = $dom->saveXML();  | 
            ||
| 107 |         if (false !== $saveXml) { | 
            ||
| 108 | return $saveXml;  | 
            ||
| 109 | }  | 
            ||
| 110 |         throw new SarbException('dom could not be saved'); // @codeCoverageIgnore | 
            ||
| 111 | }  | 
            ||
| 140 |