Source for file HTML.php
Documentation is available at HTML.php
* A doc generator that outputs documentation in one big HTML file.
* Output is in one large HTML file and is designed for you to style with
* your own stylesheet. It contains a table of contents at the top with anchors
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
namespace PHP_CodeSniffer\Generators;
use PHP_CodeSniffer\Config;
class HTML extends Generator
* Generates the documentation for a standard.
public function generate ()
foreach ($this->docFiles as $file) {
$doc = new \DOMDocument ();
$documentation = $doc->getElementsByTagName ('documentation')->item (0 );
$this->processSniff ($documentation);
* Print the header of the HTML page.
protected function printHeader ()
$standard = $this->ruleset->name;
echo " <title>$standard Coding Standards</title>".PHP_EOL;
background-color: #FFFFFF;
font-family: Arial, Helvetica, sans-serif;
background-color: #E6E7E8;
border: 1px solid #BBBBBB;
border: 1px solid #CCCCCC;
.code-comparison-title, .code-comparison-code {
font-family: Arial, Helvetica, sans-serif;
background-color: #F1F1F1;
background-color: #F9F9F9;
.code-comparison-highlight {
background-color: #DDF1F7;
border: 1px solid #00A5E3;
echo " <h1>$standard Coding Standards</h1>".PHP_EOL;
* Print the table of contents for the standard.
* The TOC is just an unordered list of bookmarks to sniffs on the page.
protected function printToc ()
echo ' <h2>Table of Contents</h2>'.PHP_EOL;
echo ' <ul class="toc">'.PHP_EOL;
foreach ($this->docFiles as $file) {
$doc = new \DOMDocument ();
$documentation = $doc->getElementsByTagName ('documentation')->item (0 );
$title = $this->getTitle ($documentation);
echo ' <li><a href="#'. str_replace(' ', '-', $title)." \">$title</a></li>".PHP_EOL;
* Print the footer of the HTML page.
protected function printFooter ()
// Turn off errors so we don't get timezone warnings if people
// don't have their timezone set.
echo ' <div class="tag-line">';
echo 'Documentation generated on '. date('r');
echo ' by <a href="https://github.com/squizlabs/PHP_CodeSniffer">PHP_CodeSniffer '.Config ::VERSION. '</a>';
* Process the documentation for a single sniff.
* @param \DOMNode $doc The DOMNode object for the sniff.
* It represents the "documentation" tag in the XML
public function processSniff (\DOMNode $doc)
$title = $this->getTitle ($doc);
echo ' <a name="'. str_replace(' ', '-', $title). '" />'.PHP_EOL;
echo " <h2>$title</h2>".PHP_EOL;
foreach ($doc->childNodes as $node) {
if ($node->nodeName === 'standard') {
$this->printTextBlock ($node);
} else if ($node->nodeName === 'code_comparison') {
$this->printCodeComparisonBlock ($node);
* Print a text block found in a standard.
* @param \DOMNode $node The DOMNode object for the text block.
protected function printTextBlock (\DOMNode $node)
$content = trim($node->nodeValue );
$content = str_replace('<em>', '<em>', $content);
$content = str_replace('</em>', '</em>', $content);
echo " <p class=\"text\">$content</p>".PHP_EOL;
* Print a code comparison block found in a standard.
* @param \DOMNode $node The DOMNode object for the code comparison block.
protected function printCodeComparisonBlock (\DOMNode $node)
$codeBlocks = $node->getElementsByTagName ('code');
$firstTitle = $codeBlocks->item (0 )->getAttribute ('title');
$first = trim($codeBlocks->item (0 )->nodeValue );
$first = str_replace('<em>', '<span class="code-comparison-highlight">', $first);
$secondTitle = $codeBlocks->item (1 )->getAttribute ('title');
$second = trim($codeBlocks->item (1 )->nodeValue );
$second = str_replace('<em>', '<span class="code-comparison-highlight">', $second);
echo ' <table class="code-comparison">'.PHP_EOL;
echo " <td class=\"code-comparison-title\">$firstTitle</td>".PHP_EOL;
echo " <td class=\"code-comparison-title\">$secondTitle</td>".PHP_EOL;
echo " <td class=\"code-comparison-code\">$first</td>".PHP_EOL;
echo " <td class=\"code-comparison-code\">$second</td>".PHP_EOL;
echo ' </table>'.PHP_EOL;
}//end printCodeComparisonBlock()
Documentation generated on Mon, 11 Mar 2019 15:27:33 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|