Ejemplo n.º 1
0
 /**
  * This method will be called when the engine has finished the source analysis
  * phase.
  *
  * @param PHP_PMD_Report $report The context violation report.
  *
  * @return void
  */
 public function renderReport(PHP_PMD_Report $report)
 {
     $writer = $this->getWriter();
     $writer->write(PHP_EOL);
     foreach ($report->getRuleViolations() as $violation) {
         $writer->write($violation->getFileName());
         $writer->write(':');
         $writer->write($violation->getBeginLine());
         $writer->write("\t");
         $writer->write($violation->getDescription());
         $writer->write(PHP_EOL);
     }
     foreach ($report->getErrors() as $error) {
         $writer->write($error->getFile());
         $writer->write("\t-\t");
         $writer->write($error->getMessage());
         $writer->write(PHP_EOL);
     }
 }
 /**
  * This method will render a html table with occurred processing errors.
  *
  * @param PHP_PMD_Report $report The context violation report.
  *
  * @return void
  * @since 1.2.1
  */
 private function glomProcessingErrors(PHP_PMD_Report $report)
 {
     if (false === $report->hasErrors()) {
         return;
     }
     $writer = $this->getWriter();
     $writer->write('<hr />');
     $writer->write('<center><h3>Processing errors</h3></center>');
     $writer->write('<table align="center" cellspacing="0" cellpadding="3">');
     $writer->write('<tr><th>File</th><th>Problem</th></tr>');
     $index = 0;
     foreach ($report->getErrors() as $error) {
         $writer->write('<tr');
         if (++$index % 2 === 1) {
             $writer->write(' bgcolor="lightgrey"');
         }
         $writer->write('>');
         $writer->write('<td>' . $error->getFile() . '</td>');
         $writer->write('<td>' . htmlentities($error->getMessage()) . '</td>');
         $writer->write('</tr>' . PHP_EOL);
     }
     $writer->write('</table>');
 }
Ejemplo n.º 3
0
 /**
  * This method will be called when the engine has finished the source analysis
  * phase.
  *
  * @param PHP_PMD_Report $report The context violation report.
  *
  * @return void
  */
 public function renderReport(PHP_PMD_Report $report)
 {
     $writer = $this->getWriter();
     $writer->write('<pmd version="' . PHP_PMD::VERSION . '" ');
     $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->getPackageName());
         $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);
     }
     $writer->write('</pmd>' . PHP_EOL);
 }
 /**
  * testGetErrorsReturnsPreviousAddedProcessingError
  *
  * @return void
  * @since 1.2.1
  */
 public function testGetErrorsReturnsPreviousAddedProcessingError()
 {
     $report = new PHP_PMD_Report();
     $report->addError(new PHP_PMD_ProcessingError('Failing file "/foo.php".'));
     $this->assertSame(1, iterator_count($report->getErrors()));
 }