Exemplo n.º 1
0
 /**
  * Prints the oxid report summary with the expected module costs.
  * 
  * @return void
  */
 public function end()
 {
     $writer = $this->getWriter();
     $this->renderLine('=');
     $writer->write(' Oxid Module Certification');
     $writer->write('                        Value');
     $writer->write('                  Factor');
     $writer->write(PHP_EOL);
     $this->renderLine('=');
     $this->renderExtremeValue('Code Coverage', $this->extremeValues->getCoverage());
     $this->renderLine('-');
     $this->renderExtremeValue('C.R.A.P Index', $this->extremeValues->getCrapIndex());
     $this->renderLine('-');
     $this->renderExtremeValue('NPath Complexity', $this->extremeValues->getNpath());
     $this->renderLine('-');
     $this->renderExtremeValue('Cyclomatic Complexity', $this->extremeValues->getCcn());
     $price = $this->certificationCost->calculate($this->extremeValues);
     $this->renderLine('=');
     $writer->write(str_repeat(' ', 55) . 'Factor:  ');
     $writer->write(sprintf('% 15s', number_format($this->extremeValues->calculateFactor(), 2, ',', '.')));
     $writer->write(PHP_EOL);
     $this->renderLine('=');
     $writer->write(str_repeat(' ', 55) . 'Price:   ');
     $writer->write(sprintf('% 15s', number_format($price, 2, ',', '.')) . PHP_EOL);
     $this->renderLine('=');
 }
Exemplo n.º 2
0
 /**
  * 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);
 }