コード例 #1
0
 /**
  * This method will be called when the engine has finished the source
  * analysis phase. To remove file with violations from cache.
  *
  * @param Report $report
  * @return void
  */
 public function renderReport(Report $report)
 {
     foreach ($report->getRuleViolations() as $violation) {
         $fileName = $violation->getFileName();
         $this->cache->remove($fileName, null);
     }
 }
コード例 #2
0
 /**
  * This method will be called when the engine has finished the source analysis
  * phase.
  *
  * @param \PHPMD\Report $report
  */
 public function renderReport(Report $report)
 {
     $this->output->writeln('');
     $groupByFile = [];
     /** @var RuleViolation $violation */
     foreach ($report->getRuleViolations() as $violation) {
         $groupByFile[$violation->getFileName()][] = $violation;
     }
     /** @var ProcessingError $error */
     foreach ($report->getErrors() as $error) {
         $groupByFile[$error->getFile()][] = $error;
     }
     foreach ($groupByFile as $file => $problems) {
         $violationCount = 0;
         $errorCount = 0;
         $table = new Table($this->output);
         $table->setStyle('borderless');
         foreach ($problems as $problem) {
             if ($problem instanceof RuleViolation) {
                 $table->addRow([$problem->getBeginLine(), '<comment>VIOLATION</comment>', $problem->getDescription()]);
                 ++$violationCount;
             }
             if ($problem instanceof ProcessingError) {
                 $table->addRow(['-', '<error>ERROR</error>', $problem->getMessage()]);
                 ++$errorCount;
             }
         }
         $this->output->writeln([sprintf('<fg=white;options=bold>FILE: %s</>', str_replace($this->basePath . '/', '', $file)), sprintf('<fg=white;options=bold>FOUND %d ERRORS AND %d VIOLATIONS</>', $errorCount, $violationCount)]);
         $table->render();
         $this->output->writeln('');
     }
 }
コード例 #3
0
 public function renderReport(Report $report)
 {
     $writer = $this->getWriter();
     foreach ($report->getRuleViolations() as $violation) {
         $rule = $violation->getRule();
         $checkName = preg_replace("/^PHPMD\\/Rule\\//", "", str_replace("\\", "/", get_class($rule)));
         $path = preg_replace("/^\\/code\\//", "", $violation->getFileName());
         $category = $this->ruleCategories[$checkName];
         if ($category == null) {
             $category = "Style";
         }
         $issue = array("type" => "issue", "check_name" => $checkName, "description" => $violation->getDescription(), "categories" => array($category), "location" => array("path" => $path, "lines" => array("begin" => $violation->getBeginLine(), "end" => $violation->getEndLine())));
         $json = json_encode($issue, JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE);
         $writer->write($json);
         $writer->write(chr(0));
     }
 }
コード例 #4
0
ファイル: TextRenderer.php プロジェクト: phpmd/phpmd
 /**
  * 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)
 {
     $writer = $this->getWriter();
     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);
     }
 }
コード例 #5
0
 public function renderReport(Report $report)
 {
     $writer = $this->getWriter();
     foreach ($report->getRuleViolations() as $violation) {
         $rule = $violation->getRule();
         $checkName = preg_replace("/^PHPMD\\/Rule\\//", "", str_replace("\\", "/", get_class($rule)));
         $path = preg_replace("/^\\/code\\//", "", $violation->getFileName());
         $category = Category::categoryFor($checkName);
         $metric = $violation->getMetric();
         $points = Category::pointsFor($checkName, $metric);
         $content = Category::documentationFor($checkName);
         $issue = array("type" => "issue", "check_name" => $checkName, "description" => $violation->getDescription(), "categories" => array($category), "remediation_points" => $points, "location" => array("path" => $path, "lines" => array("begin" => $violation->getBeginLine(), "end" => $violation->getEndLine())));
         if ($content) {
             $issue["content"] = array("body" => $content);
         }
         $json = json_encode($issue, JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE);
         $writer->write($json);
         $writer->write(chr(0));
     }
 }
コード例 #6
0
ファイル: TextRenderer.php プロジェクト: MantasVaitkunas/oxmd
 /**
  * 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);
     }
 }
コード例 #7
0
ファイル: XMLRenderer.php プロジェクト: flavius/phpmd
 /**
  * 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)
 {
     $writer = $this->getWriter();
     $writer->write('<pmd version="' . PHPMD::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->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);
     }
     $writer->write('</pmd>' . PHP_EOL);
 }
コード例 #8
0
 /**
  * This method will render a html table with occurred processing errors.
  *
  * @param \PHPMD\Report $report
  * @return void
  * @since 1.2.1
  */
 private function glomProcessingErrors(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>');
 }
コード例 #9
0
ファイル: AbstractRule.php プロジェクト: Flesh192/magento
 /**
  * This method adds a violation to all reports for this violation type and
  * for the given <b>$node</b> instance.
  *
  * @param \PHPMD\AbstractNode $node
  * @param array $args
  * @param mixed $metric
  * @return void
  */
 protected function addViolation(AbstractNode $node, array $args = array(), $metric = null)
 {
     $search = array();
     $replace = array();
     foreach ($args as $index => $value) {
         $search[] = '{' . $index . '}';
         $replace[] = $value;
     }
     $message = str_replace($search, $replace, $this->message);
     $ruleViolation = new RuleViolation($this, $node, $message, $metric);
     $this->report->addRuleViolation($ruleViolation);
 }
コード例 #10
0
ファイル: XmlRenderer.php プロジェクト: MantasVaitkunas/oxmd
 /**
  * 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);
 }