Question

Does PHPCodeSniffer generates HTML Report?

If not? How?

Currently, I can run PHPCodeSniffer but it only produce XML file and displays result in the terminal.

How can I make produce HTML Report like the coverage and unit test report in phpunit.

Currently I use PHPCheckStyle since it produces html report, but i want also to try PHPCodeSniffer to know which is best.

Was it helpful?

Solution

Another solution (but maybe not the simplest one) is to use a continuous integration system that provides PHP code sniffer integration.

For example, phpUnderControl provides a nice interface to see the report.

phpUnderControl

OTHER TIPS

HTML Reporting is not provided yet. However there is a workaround to get the job done.

You can export the report to XML and read the data with DOM Parser and generate an HTML version on your own. Here is a quick tutorial to get you started.

Writing your own report is pretty trivial actually.

If you are running from CLI you can implement your own report class with a unique method and call it from command ligne. For a report named Xxx :

class PHP_CodeSniffer_Reports_Xxx implements PHP_CodeSniffer_Report
{ 

  /**
   * Prints all errors and warnings for each file processed.
   *
   * Errors and warnings are displayed together, grouped by file.
   *
   * @param array   $report      Prepared report.
   * @param boolean $showSources Show sources?
   * @param int     $width       Maximum allowed lne width.
   * @param boolean $toScreen    Is the report being printed to screen?
   *
   * @return string
   */
  public function generate(
      $report,
      $showSources=false,
      $width=80,
      $toScreen=true
  ) {
     ...
  }
}

If your are running from a web server, the PHP_CodeSniffer.getFilesErrors() method gives you a nice array of errors with all you need to produce a report.

HTML Reporting is working for me. Just use according --help:

phpcs src/AppBundle --generator=HTML > index.html

Show the result in index.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top