Source for file Markdown.php
Documentation is available at Markdown.php
* A doc generator that outputs documentation in Markdown format.
* @author Stefano Kowalke <blueduck@gmx.net>
* @copyright 2014 Arroba IT
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
namespace PHP_CodeSniffer\Generators;
use PHP_CodeSniffer\Config;
class Markdown 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 markdown header.
protected function printHeader ()
$standard = $this->ruleset->name;
echo " # $standard Coding Standard".PHP_EOL;
* Print the markdown footer.
protected function printFooter ()
// Turn off errors so we don't get timezone warnings if people
// don't have their timezone set.
echo 'Documentation generated on '. date('r');
echo ' by [PHP_CodeSniffer '.Config ::VERSION. '](https://github.com/squizlabs/PHP_CodeSniffer)'.PHP_EOL;
* Process the documentation for a single sniff.
* @param \DOMNode $doc The DOMNode object for the sniff.
* It represents the "documentation" tag in the XML
protected function processSniff (\DOMNode $doc)
$title = $this->getTitle ($doc);
echo " ## $title".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 );
* 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 );
$secondTitle = $codeBlocks->item (1 )->getAttribute ('title');
$second = trim($codeBlocks->item (1 )->nodeValue );
echo " <th>$firstTitle</th>".PHP_EOL;
echo " <th>$secondTitle</th>".PHP_EOL;
echo '<td>'.PHP_EOL.PHP_EOL;
echo " $first".PHP_EOL.PHP_EOL;
echo '<td>'.PHP_EOL.PHP_EOL;
echo " $second".PHP_EOL.PHP_EOL;
echo ' </table>'.PHP_EOL;
}//end printCodeComparisonBlock()
Documentation generated on Mon, 11 Mar 2019 15:27:37 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|