/** * This method will be called when the engine has finished the source analysis * phase. * * @param \PHPMD\Report $report * @return void */ public function renderReport(Report $report) { $this->extremeValues = ExtremeValues::createFromViolations($report->getRuleViolations()); $writer = $this->getWriter(); $writer->write('<pmd '); $writer->write('xmlns:oxid="http://wiki.oxidforge.org/Certification/Modules" '); $writer->write('oxid:version="' . Version::getOxmdVersion() . '" '); $writer->write('version="' . Version::getPhpmdVersion() . '" '); $writer->write('timestamp="' . date('c') . '">'); $writer->write(PHP_EOL); foreach ($report->getRuleViolations() as $violation) { $fileName = $violation->getFileName(); if ($this->fileName !== $fileName) { // Not first file if ($this->fileName !== null) { $writer->write(' </file>' . PHP_EOL); } // Store current file name $this->fileName = $fileName; $writer->write(' <file name="' . $fileName . '">' . PHP_EOL); } $rule = $violation->getRule(); $writer->write(' <violation'); $writer->write(' beginline="' . $violation->getBeginLine() . '"'); $writer->write(' endline="' . $violation->getEndLine() . '"'); $writer->write(' rule="' . $rule->getName() . '"'); $writer->write(' ruleset="' . $rule->getRuleSetName() . '"'); $this->maybeAdd('package', $violation->getNamespaceName()); $this->maybeAdd('externalInfoUrl', $rule->getExternalInfoUrl()); $this->maybeAdd('function', $violation->getFunctionName()); $this->maybeAdd('class', $violation->getClassName()); $this->maybeAdd('method', $violation->getMethodName()); //$this->_maybeAdd('variable', $violation->getVariableName()); $writer->write(' priority="' . $rule->getPriority() . '"'); $writer->write('>' . PHP_EOL); $writer->write(' ' . $violation->getDescription() . PHP_EOL); $writer->write(' </violation>' . PHP_EOL); } // Last file and at least one violation if ($this->fileName !== null) { $writer->write(' </file>' . PHP_EOL); } foreach ($report->getErrors() as $error) { $writer->write(' <error filename="'); $writer->write($error->getFile()); $writer->write('" msg="'); $writer->write(htmlspecialchars($error->getMessage())); $writer->write('" />' . PHP_EOL); } if ($this->extremeValues->calculateFactor() > 1.0) { $writer->write(PHP_EOL); $writer->write(' <oxid:certification factor="'); $writer->write($this->extremeValues->calculateFactor()); $writer->write('" price="'); $writer->write($this->certificationCost->calculate($this->extremeValues)); $writer->write('">' . PHP_EOL); $this->renderExtremeValue('Code Coverage', $this->extremeValues->getCoverage()); $this->renderExtremeValue('C.R.A.P Index', $this->extremeValues->getCrapIndex()); $this->renderExtremeValue('NPath Complexity', $this->extremeValues->getNpath()); $this->renderExtremeValue('Cyclomatic Complexity', $this->extremeValues->getCcn()); $writer->write(' </oxid:certification>' . PHP_EOL); } $writer->write('</pmd>' . PHP_EOL); }
/** * This method will be called when the engine has finished the source analysis * phase. * * @param \PHPMD\Report $report * @return void */ public function renderReport(Report $report) { $this->extremeValues = ExtremeValues::createFromViolations($report->getRuleViolations()); $writer = $this->getWriter(); $writer->write(PHP_EOL); foreach ($report->getRuleViolations() as $violation) { $this->renderLine('='); $this->renderPath($violation->getFileName(), $violation->getBeginLine()); $this->renderLine('='); $writer->write(wordwrap($violation->getDescription(), 80)); $writer->write(PHP_EOL); $writer->write(PHP_EOL); } }