3

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.

hakre
  • 193,403
  • 52
  • 435
  • 836
Annie B.
  • 275
  • 1
  • 6
  • 13
  • Sorry for that question. What I meant for that is If PHPCodeSniffer does not generate HTML Report, how can we do it so that it will produce HTML report, is there a way? or will i just wait for future versions that supports that functionality... I apologize for that invalid question. – Annie B. Dec 29 '11 at 07:38
  • This is actually a duplicate of http://stackoverflow.com/questions/1831535/how-can-i-convert-php-code-sniffer-xml-report-into-html which has a real answer to that question. – markus Feb 21 '12 at 15:58

4 Answers4

3

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

Matthieu Napoli
  • 48,448
  • 45
  • 173
  • 261
2

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.

Matthieu Napoli
  • 48,448
  • 45
  • 173
  • 261
Starx
  • 77,474
  • 47
  • 185
  • 261
2

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.

Tom Desp
  • 911
  • 6
  • 19
-1

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

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

Show the result in index.html

Aize
  • 510
  • 3
  • 10
  • Generator is used to force create documentation of your rules, not for generating report in HTML - see doc: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage Uses either the "HTML", "Markdown" or "Text" generator (forces documentation generation instead of checking) you could use report now but it's not support HTML - Print either the "full", "xml", "checkstyle", "csv" "json", "junit", "emacs", "source", "summary", "diff" "svnblame", "gitblame", "hgblame" or "notifysend" report – Paweł Liszka Jul 18 '17 at 15:47