コード例 #1
0
ファイル: TextRenderer.php プロジェクト: Tjorriemorrie/app
 /**
  * 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);
     }
 }
コード例 #2
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)
 {
     $index = 0;
     $writer = $this->getWriter();
     foreach ($report->getRuleViolations() as $violation) {
         $writer->write('<tr');
         if (++$index % 2 === 1) {
             $writer->write(' bgcolor="lightgrey"');
         }
         $writer->write('>');
         $writer->write(PHP_EOL);
         $writer->write('<td align="center">');
         $writer->write($index);
         $writer->write('</td>');
         $writer->write(PHP_EOL);
         $writer->write('<td>');
         $writer->write(htmlentities($violation->getFileName()));
         $writer->write('</td>');
         $writer->write(PHP_EOL);
         $writer->write('<td align="center" width="5%">');
         $writer->write($violation->getBeginLine());
         $writer->write('</td>');
         $writer->write(PHP_EOL);
         $writer->write('<td>');
         if ($violation->getRule()->getExternalInfoUrl()) {
             $writer->write('<a href="');
             $writer->write($violation->getRule()->getExternalInfoUrl());
             $writer->write('">');
         }
         $writer->write(htmlentities($violation->getDescription()));
         if ($violation->getRule()->getExternalInfoUrl()) {
             $writer->write('</a>');
         }
         $writer->write('</td>');
         $writer->write(PHP_EOL);
         $writer->write('</tr>');
         $writer->write(PHP_EOL);
     }
     $writer->write('</table>');
     $this->glomProcessingErrors($report);
 }
コード例 #3
0
ファイル: XMLRenderer.php プロジェクト: kingsj/core
 /**
  * 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);
     }
     $writer->write('</pmd>' . PHP_EOL);
 }
コード例 #4
0
ファイル: ReportTest.php プロジェクト: kingsj/core
 /**
  * Tests that the report returns the result by the violation line number.
  *
  * @return void
  * @covers PHP_PMD_Report
  * @group phpmd
  * @group unittest
  */
 public function testReportSortsResultByLineNumber()
 {
     $report = new PHP_PMD_Report();
     $report->addRuleViolation($this->getRuleViolationMock('foo.txt', 4, 5));
     $report->addRuleViolation($this->getRuleViolationMock('foo.txt', 1, 2));
     $report->addRuleViolation($this->getRuleViolationMock('foo.txt', 3, 6));
     $report->addRuleViolation($this->getRuleViolationMock('foo.txt', 2, 3));
     $report->addRuleViolation($this->getRuleViolationMock('bar.txt', 2, 3));
     $report->addRuleViolation($this->getRuleViolationMock('bar.txt', 1, 2));
     $actual = array();
     foreach ($report->getRuleViolations() as $violation) {
         $actual[] = array($violation->getFileName(), $violation->getBeginLine(), $violation->getEndLine());
     }
     $expected = array(array('bar.txt', 1, 2), array('bar.txt', 2, 3), array('foo.txt', 1, 2), array('foo.txt', 2, 3), array('foo.txt', 3, 6), array('foo.txt', 4, 5));
     $this->assertSame($expected, $actual);
 }