more updates yay
This commit is contained in:
118
vendor/squizlabs/php_codesniffer/src/Generators/Generator.php
vendored
Normal file
118
vendor/squizlabs/php_codesniffer/src/Generators/Generator.php
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
* The base class for all PHP_CodeSniffer documentation generators.
|
||||
*
|
||||
* Documentation generators are used to print documentation about code sniffs
|
||||
* in a standard.
|
||||
*
|
||||
* @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\Ruleset;
|
||||
use PHP_CodeSniffer\Autoload;
|
||||
use PHP_CodeSniffer\Util\Common;
|
||||
|
||||
abstract class Generator
|
||||
{
|
||||
|
||||
/**
|
||||
* The ruleset used for the run.
|
||||
*
|
||||
* @var \PHP_CodeSniffer\Ruleset
|
||||
*/
|
||||
public $ruleset = null;
|
||||
|
||||
/**
|
||||
* XML documentation files used to produce the final output.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public $docFiles = [];
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a doc generator.
|
||||
*
|
||||
* @param \PHP_CodeSniffer\Ruleset $ruleset The ruleset used for the run.
|
||||
*
|
||||
* @see generate()
|
||||
*/
|
||||
public function __construct(Ruleset $ruleset)
|
||||
{
|
||||
$this->ruleset = $ruleset;
|
||||
|
||||
foreach ($ruleset->sniffs as $className => $sniffClass) {
|
||||
$file = Autoload::getLoadedFileName($className);
|
||||
$docFile = str_replace(
|
||||
DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR,
|
||||
DIRECTORY_SEPARATOR.'Docs'.DIRECTORY_SEPARATOR,
|
||||
$file
|
||||
);
|
||||
$docFile = str_replace('Sniff.php', 'Standard.xml', $docFile);
|
||||
|
||||
if (is_file($docFile) === true) {
|
||||
$this->docFiles[] = $docFile;
|
||||
}
|
||||
}
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the title of the sniff from the DOMNode supplied.
|
||||
*
|
||||
* @param \DOMNode $doc The DOMNode object for the sniff.
|
||||
* It represents the "documentation" tag in the XML
|
||||
* standard file.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTitle(\DOMNode $doc)
|
||||
{
|
||||
return $doc->getAttribute('title');
|
||||
|
||||
}//end getTitle()
|
||||
|
||||
|
||||
/**
|
||||
* Generates the documentation for a standard.
|
||||
*
|
||||
* It's probably wise for doc generators to override this method so they
|
||||
* have control over how the docs are produced. Otherwise, the processSniff
|
||||
* method should be overridden to output content for each sniff.
|
||||
*
|
||||
* @return void
|
||||
* @see processSniff()
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
foreach ($this->docFiles as $file) {
|
||||
$doc = new \DOMDocument();
|
||||
$doc->load($file);
|
||||
$documentation = $doc->getElementsByTagName('documentation')->item(0);
|
||||
$this->processSniff($documentation);
|
||||
}
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
/**
|
||||
* Process the documentation for a single sniff.
|
||||
*
|
||||
* Doc generators must implement this function to produce output.
|
||||
*
|
||||
* @param \DOMNode $doc The DOMNode object for the sniff.
|
||||
* It represents the "documentation" tag in the XML
|
||||
* standard file.
|
||||
*
|
||||
* @return void
|
||||
* @see generate()
|
||||
*/
|
||||
abstract protected function processSniff(\DOMNode $doc);
|
||||
|
||||
|
||||
}//end class
|
270
vendor/squizlabs/php_codesniffer/src/Generators/HTML.php
vendored
Normal file
270
vendor/squizlabs/php_codesniffer/src/Generators/HTML.php
vendored
Normal file
@ -0,0 +1,270 @@
|
||||
<?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
|
||||
* to each sniff.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @return void
|
||||
* @see processSniff()
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
ob_start();
|
||||
$this->printHeader();
|
||||
$this->printToc();
|
||||
|
||||
foreach ($this->docFiles as $file) {
|
||||
$doc = new \DOMDocument();
|
||||
$doc->load($file);
|
||||
$documentation = $doc->getElementsByTagName('documentation')->item(0);
|
||||
$this->processSniff($documentation);
|
||||
}
|
||||
|
||||
$this->printFooter();
|
||||
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
echo $content;
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
/**
|
||||
* Print the header of the HTML page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function printHeader()
|
||||
{
|
||||
$standard = $this->ruleset->name;
|
||||
echo '<html>'.PHP_EOL;
|
||||
echo ' <head>'.PHP_EOL;
|
||||
echo " <title>$standard Coding Standards</title>".PHP_EOL;
|
||||
echo ' <style>
|
||||
body {
|
||||
background-color: #FFFFFF;
|
||||
font-size: 14px;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #666666;
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
margin-top: 0px;
|
||||
background-color: #E6E7E8;
|
||||
padding: 20px;
|
||||
border: 1px solid #BBBBBB;
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: #00A5E3;
|
||||
font-size: 16px;
|
||||
font-weight: normal;
|
||||
margin-top: 50px;
|
||||
}
|
||||
|
||||
.code-comparison {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.code-comparison td {
|
||||
border: 1px solid #CCCCCC;
|
||||
}
|
||||
|
||||
.code-comparison-title, .code-comparison-code {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
font-size: 12px;
|
||||
color: #000000;
|
||||
vertical-align: top;
|
||||
padding: 4px;
|
||||
width: 50%;
|
||||
background-color: #F1F1F1;
|
||||
line-height: 15px;
|
||||
}
|
||||
|
||||
.code-comparison-code {
|
||||
font-family: Courier;
|
||||
background-color: #F9F9F9;
|
||||
}
|
||||
|
||||
.code-comparison-highlight {
|
||||
background-color: #DDF1F7;
|
||||
border: 1px solid #00A5E3;
|
||||
line-height: 15px;
|
||||
}
|
||||
|
||||
.tag-line {
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
margin-top: 30px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.tag-line a {
|
||||
color: #000000;
|
||||
}
|
||||
</style>'.PHP_EOL;
|
||||
echo ' </head>'.PHP_EOL;
|
||||
echo ' <body>'.PHP_EOL;
|
||||
echo " <h1>$standard Coding Standards</h1>".PHP_EOL;
|
||||
|
||||
}//end printHeader()
|
||||
|
||||
|
||||
/**
|
||||
* Print the table of contents for the standard.
|
||||
*
|
||||
* The TOC is just an unordered list of bookmarks to sniffs on the page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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();
|
||||
$doc->load($file);
|
||||
$documentation = $doc->getElementsByTagName('documentation')->item(0);
|
||||
$title = $this->getTitle($documentation);
|
||||
echo ' <li><a href="#'.str_replace(' ', '-', $title)."\">$title</a></li>".PHP_EOL;
|
||||
}
|
||||
|
||||
echo ' </ul>'.PHP_EOL;
|
||||
|
||||
}//end printToc()
|
||||
|
||||
|
||||
/**
|
||||
* Print the footer of the HTML page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function printFooter()
|
||||
{
|
||||
// Turn off errors so we don't get timezone warnings if people
|
||||
// don't have their timezone set.
|
||||
$errorLevel = error_reporting(0);
|
||||
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>';
|
||||
echo '</div>'.PHP_EOL;
|
||||
error_reporting($errorLevel);
|
||||
|
||||
echo ' </body>'.PHP_EOL;
|
||||
echo '</html>'.PHP_EOL;
|
||||
|
||||
}//end printFooter()
|
||||
|
||||
|
||||
/**
|
||||
* Process the documentation for a single sniff.
|
||||
*
|
||||
* @param \DOMNode $doc The DOMNode object for the sniff.
|
||||
* It represents the "documentation" tag in the XML
|
||||
* standard file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}//end processSniff()
|
||||
|
||||
|
||||
/**
|
||||
* Print a text block found in a standard.
|
||||
*
|
||||
* @param \DOMNode $node The DOMNode object for the text block.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function printTextBlock(\DOMNode $node)
|
||||
{
|
||||
$content = trim($node->nodeValue);
|
||||
$content = htmlspecialchars($content);
|
||||
|
||||
// Allow em tags only.
|
||||
$content = str_replace('<em>', '<em>', $content);
|
||||
$content = str_replace('</em>', '</em>', $content);
|
||||
|
||||
echo " <p class=\"text\">$content</p>".PHP_EOL;
|
||||
|
||||
}//end printTextBlock()
|
||||
|
||||
|
||||
/**
|
||||
* Print a code comparison block found in a standard.
|
||||
*
|
||||
* @param \DOMNode $node The DOMNode object for the code comparison block.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function printCodeComparisonBlock(\DOMNode $node)
|
||||
{
|
||||
$codeBlocks = $node->getElementsByTagName('code');
|
||||
|
||||
$firstTitle = $codeBlocks->item(0)->getAttribute('title');
|
||||
$first = trim($codeBlocks->item(0)->nodeValue);
|
||||
$first = str_replace('<?php', '<?php', $first);
|
||||
$first = str_replace("\n", '</br>', $first);
|
||||
$first = str_replace(' ', ' ', $first);
|
||||
$first = str_replace('<em>', '<span class="code-comparison-highlight">', $first);
|
||||
$first = str_replace('</em>', '</span>', $first);
|
||||
|
||||
$secondTitle = $codeBlocks->item(1)->getAttribute('title');
|
||||
$second = trim($codeBlocks->item(1)->nodeValue);
|
||||
$second = str_replace('<?php', '<?php', $second);
|
||||
$second = str_replace("\n", '</br>', $second);
|
||||
$second = str_replace(' ', ' ', $second);
|
||||
$second = str_replace('<em>', '<span class="code-comparison-highlight">', $second);
|
||||
$second = str_replace('</em>', '</span>', $second);
|
||||
|
||||
echo ' <table class="code-comparison">'.PHP_EOL;
|
||||
echo ' <tr>'.PHP_EOL;
|
||||
echo " <td class=\"code-comparison-title\">$firstTitle</td>".PHP_EOL;
|
||||
echo " <td class=\"code-comparison-title\">$secondTitle</td>".PHP_EOL;
|
||||
echo ' </tr>'.PHP_EOL;
|
||||
echo ' <tr>'.PHP_EOL;
|
||||
echo " <td class=\"code-comparison-code\">$first</td>".PHP_EOL;
|
||||
echo " <td class=\"code-comparison-code\">$second</td>".PHP_EOL;
|
||||
echo ' </tr>'.PHP_EOL;
|
||||
echo ' </table>'.PHP_EOL;
|
||||
|
||||
}//end printCodeComparisonBlock()
|
||||
|
||||
|
||||
}//end class
|
161
vendor/squizlabs/php_codesniffer/src/Generators/Markdown.php
vendored
Normal file
161
vendor/squizlabs/php_codesniffer/src/Generators/Markdown.php
vendored
Normal file
@ -0,0 +1,161 @@
|
||||
<?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.
|
||||
*
|
||||
* @return void
|
||||
* @see processSniff()
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
ob_start();
|
||||
$this->printHeader();
|
||||
|
||||
foreach ($this->docFiles as $file) {
|
||||
$doc = new \DOMDocument();
|
||||
$doc->load($file);
|
||||
$documentation = $doc->getElementsByTagName('documentation')->item(0);
|
||||
$this->processSniff($documentation);
|
||||
}
|
||||
|
||||
$this->printFooter();
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
echo $content;
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
/**
|
||||
* Print the markdown header.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function printHeader()
|
||||
{
|
||||
$standard = $this->ruleset->name;
|
||||
|
||||
echo "# $standard Coding Standard".PHP_EOL;
|
||||
|
||||
}//end printHeader()
|
||||
|
||||
|
||||
/**
|
||||
* Print the markdown footer.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function printFooter()
|
||||
{
|
||||
// Turn off errors so we don't get timezone warnings if people
|
||||
// don't have their timezone set.
|
||||
error_reporting(0);
|
||||
echo 'Documentation generated on '.date('r');
|
||||
echo ' by [PHP_CodeSniffer '.Config::VERSION.'](https://github.com/squizlabs/PHP_CodeSniffer)'.PHP_EOL;
|
||||
|
||||
}//end printFooter()
|
||||
|
||||
|
||||
/**
|
||||
* Process the documentation for a single sniff.
|
||||
*
|
||||
* @param \DOMNode $doc The DOMNode object for the sniff.
|
||||
* It represents the "documentation" tag in the XML
|
||||
* standard file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}//end processSniff()
|
||||
|
||||
|
||||
/**
|
||||
* Print a text block found in a standard.
|
||||
*
|
||||
* @param \DOMNode $node The DOMNode object for the text block.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function printTextBlock(\DOMNode $node)
|
||||
{
|
||||
$content = trim($node->nodeValue);
|
||||
$content = htmlspecialchars($content);
|
||||
|
||||
$content = str_replace('<em>', '*', $content);
|
||||
$content = str_replace('</em>', '*', $content);
|
||||
|
||||
echo $content.PHP_EOL;
|
||||
|
||||
}//end printTextBlock()
|
||||
|
||||
|
||||
/**
|
||||
* Print a code comparison block found in a standard.
|
||||
*
|
||||
* @param \DOMNode $node The DOMNode object for the code comparison block.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function printCodeComparisonBlock(\DOMNode $node)
|
||||
{
|
||||
$codeBlocks = $node->getElementsByTagName('code');
|
||||
|
||||
$firstTitle = $codeBlocks->item(0)->getAttribute('title');
|
||||
$first = trim($codeBlocks->item(0)->nodeValue);
|
||||
$first = str_replace("\n", "\n ", $first);
|
||||
$first = str_replace('<em>', '', $first);
|
||||
$first = str_replace('</em>', '', $first);
|
||||
|
||||
$secondTitle = $codeBlocks->item(1)->getAttribute('title');
|
||||
$second = trim($codeBlocks->item(1)->nodeValue);
|
||||
$second = str_replace("\n", "\n ", $second);
|
||||
$second = str_replace('<em>', '', $second);
|
||||
$second = str_replace('</em>', '', $second);
|
||||
|
||||
echo ' <table>'.PHP_EOL;
|
||||
echo ' <tr>'.PHP_EOL;
|
||||
echo " <th>$firstTitle</th>".PHP_EOL;
|
||||
echo " <th>$secondTitle</th>".PHP_EOL;
|
||||
echo ' </tr>'.PHP_EOL;
|
||||
echo ' <tr>'.PHP_EOL;
|
||||
echo '<td>'.PHP_EOL.PHP_EOL;
|
||||
echo " $first".PHP_EOL.PHP_EOL;
|
||||
echo '</td>'.PHP_EOL;
|
||||
echo '<td>'.PHP_EOL.PHP_EOL;
|
||||
echo " $second".PHP_EOL.PHP_EOL;
|
||||
echo '</td>'.PHP_EOL;
|
||||
echo ' </tr>'.PHP_EOL;
|
||||
echo ' </table>'.PHP_EOL;
|
||||
|
||||
}//end printCodeComparisonBlock()
|
||||
|
||||
|
||||
}//end class
|
245
vendor/squizlabs/php_codesniffer/src/Generators/Text.php
vendored
Normal file
245
vendor/squizlabs/php_codesniffer/src/Generators/Text.php
vendored
Normal file
@ -0,0 +1,245 @@
|
||||
<?php
|
||||
/**
|
||||
* A doc generator that outputs text-based documentation.
|
||||
*
|
||||
* Output is designed to be displayed in a terminal and is wrapped to 100 characters.
|
||||
*
|
||||
* @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;
|
||||
|
||||
class Text extends Generator
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Process the documentation for a single sniff.
|
||||
*
|
||||
* @param \DOMNode $doc The DOMNode object for the sniff.
|
||||
* It represents the "documentation" tag in the XML
|
||||
* standard file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function processSniff(\DOMNode $doc)
|
||||
{
|
||||
$this->printTitle($doc);
|
||||
|
||||
foreach ($doc->childNodes as $node) {
|
||||
if ($node->nodeName === 'standard') {
|
||||
$this->printTextBlock($node);
|
||||
} else if ($node->nodeName === 'code_comparison') {
|
||||
$this->printCodeComparisonBlock($node);
|
||||
}
|
||||
}
|
||||
|
||||
}//end processSniff()
|
||||
|
||||
|
||||
/**
|
||||
* Prints the title area for a single sniff.
|
||||
*
|
||||
* @param \DOMNode $doc The DOMNode object for the sniff.
|
||||
* It represents the "documentation" tag in the XML
|
||||
* standard file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function printTitle(\DOMNode $doc)
|
||||
{
|
||||
$title = $this->getTitle($doc);
|
||||
$standard = $this->ruleset->name;
|
||||
|
||||
echo PHP_EOL;
|
||||
echo str_repeat('-', (strlen("$standard CODING STANDARD: $title") + 4));
|
||||
echo strtoupper(PHP_EOL."| $standard CODING STANDARD: $title |".PHP_EOL);
|
||||
echo str_repeat('-', (strlen("$standard CODING STANDARD: $title") + 4));
|
||||
echo PHP_EOL.PHP_EOL;
|
||||
|
||||
}//end printTitle()
|
||||
|
||||
|
||||
/**
|
||||
* Print a text block found in a standard.
|
||||
*
|
||||
* @param \DOMNode $node The DOMNode object for the text block.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function printTextBlock(\DOMNode $node)
|
||||
{
|
||||
$text = trim($node->nodeValue);
|
||||
$text = str_replace('<em>', '*', $text);
|
||||
$text = str_replace('</em>', '*', $text);
|
||||
|
||||
$lines = [];
|
||||
$tempLine = '';
|
||||
$words = explode(' ', $text);
|
||||
|
||||
foreach ($words as $word) {
|
||||
if (strlen($tempLine.$word) >= 99) {
|
||||
if (strlen($tempLine.$word) === 99) {
|
||||
// Adding the extra space will push us to the edge
|
||||
// so we are done.
|
||||
$lines[] = $tempLine.$word;
|
||||
$tempLine = '';
|
||||
} else if (strlen($tempLine.$word) === 100) {
|
||||
// We are already at the edge, so we are done.
|
||||
$lines[] = $tempLine.$word;
|
||||
$tempLine = '';
|
||||
} else {
|
||||
$lines[] = rtrim($tempLine);
|
||||
$tempLine = $word.' ';
|
||||
}
|
||||
} else {
|
||||
$tempLine .= $word.' ';
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
if ($tempLine !== '') {
|
||||
$lines[] = rtrim($tempLine);
|
||||
}
|
||||
|
||||
echo implode(PHP_EOL, $lines).PHP_EOL.PHP_EOL;
|
||||
|
||||
}//end printTextBlock()
|
||||
|
||||
|
||||
/**
|
||||
* Print a code comparison block found in a standard.
|
||||
*
|
||||
* @param \DOMNode $node The DOMNode object for the code comparison block.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function printCodeComparisonBlock(\DOMNode $node)
|
||||
{
|
||||
$codeBlocks = $node->getElementsByTagName('code');
|
||||
$first = trim($codeBlocks->item(0)->nodeValue);
|
||||
$firstTitle = $codeBlocks->item(0)->getAttribute('title');
|
||||
|
||||
$firstTitleLines = [];
|
||||
$tempTitle = '';
|
||||
$words = explode(' ', $firstTitle);
|
||||
|
||||
foreach ($words as $word) {
|
||||
if (strlen($tempTitle.$word) >= 45) {
|
||||
if (strlen($tempTitle.$word) === 45) {
|
||||
// Adding the extra space will push us to the edge
|
||||
// so we are done.
|
||||
$firstTitleLines[] = $tempTitle.$word;
|
||||
$tempTitle = '';
|
||||
} else if (strlen($tempTitle.$word) === 46) {
|
||||
// We are already at the edge, so we are done.
|
||||
$firstTitleLines[] = $tempTitle.$word;
|
||||
$tempTitle = '';
|
||||
} else {
|
||||
$firstTitleLines[] = $tempTitle;
|
||||
$tempTitle = $word;
|
||||
}
|
||||
} else {
|
||||
$tempTitle .= $word.' ';
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
if ($tempTitle !== '') {
|
||||
$firstTitleLines[] = $tempTitle;
|
||||
}
|
||||
|
||||
$first = str_replace('<em>', '', $first);
|
||||
$first = str_replace('</em>', '', $first);
|
||||
$firstLines = explode("\n", $first);
|
||||
|
||||
$second = trim($codeBlocks->item(1)->nodeValue);
|
||||
$secondTitle = $codeBlocks->item(1)->getAttribute('title');
|
||||
|
||||
$secondTitleLines = [];
|
||||
$tempTitle = '';
|
||||
$words = explode(' ', $secondTitle);
|
||||
|
||||
foreach ($words as $word) {
|
||||
if (strlen($tempTitle.$word) >= 45) {
|
||||
if (strlen($tempTitle.$word) === 45) {
|
||||
// Adding the extra space will push us to the edge
|
||||
// so we are done.
|
||||
$secondTitleLines[] = $tempTitle.$word;
|
||||
$tempTitle = '';
|
||||
} else if (strlen($tempTitle.$word) === 46) {
|
||||
// We are already at the edge, so we are done.
|
||||
$secondTitleLines[] = $tempTitle.$word;
|
||||
$tempTitle = '';
|
||||
} else {
|
||||
$secondTitleLines[] = $tempTitle;
|
||||
$tempTitle = $word;
|
||||
}
|
||||
} else {
|
||||
$tempTitle .= $word.' ';
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
if ($tempTitle !== '') {
|
||||
$secondTitleLines[] = $tempTitle;
|
||||
}
|
||||
|
||||
$second = str_replace('<em>', '', $second);
|
||||
$second = str_replace('</em>', '', $second);
|
||||
$secondLines = explode("\n", $second);
|
||||
|
||||
$maxCodeLines = max(count($firstLines), count($secondLines));
|
||||
$maxTitleLines = max(count($firstTitleLines), count($secondTitleLines));
|
||||
|
||||
echo str_repeat('-', 41);
|
||||
echo ' CODE COMPARISON ';
|
||||
echo str_repeat('-', 42).PHP_EOL;
|
||||
|
||||
for ($i = 0; $i < $maxTitleLines; $i++) {
|
||||
if (isset($firstTitleLines[$i]) === true) {
|
||||
$firstLineText = $firstTitleLines[$i];
|
||||
} else {
|
||||
$firstLineText = '';
|
||||
}
|
||||
|
||||
if (isset($secondTitleLines[$i]) === true) {
|
||||
$secondLineText = $secondTitleLines[$i];
|
||||
} else {
|
||||
$secondLineText = '';
|
||||
}
|
||||
|
||||
echo '| ';
|
||||
echo $firstLineText.str_repeat(' ', (46 - strlen($firstLineText)));
|
||||
echo ' | ';
|
||||
echo $secondLineText.str_repeat(' ', (47 - strlen($secondLineText)));
|
||||
echo ' |'.PHP_EOL;
|
||||
}//end for
|
||||
|
||||
echo str_repeat('-', 100).PHP_EOL;
|
||||
|
||||
for ($i = 0; $i < $maxCodeLines; $i++) {
|
||||
if (isset($firstLines[$i]) === true) {
|
||||
$firstLineText = $firstLines[$i];
|
||||
} else {
|
||||
$firstLineText = '';
|
||||
}
|
||||
|
||||
if (isset($secondLines[$i]) === true) {
|
||||
$secondLineText = $secondLines[$i];
|
||||
} else {
|
||||
$secondLineText = '';
|
||||
}
|
||||
|
||||
echo '| ';
|
||||
echo $firstLineText.str_repeat(' ', (47 - strlen($firstLineText)));
|
||||
echo '| ';
|
||||
echo $secondLineText.str_repeat(' ', (48 - strlen($secondLineText)));
|
||||
echo '|'.PHP_EOL;
|
||||
}//end for
|
||||
|
||||
echo str_repeat('-', 100).PHP_EOL.PHP_EOL;
|
||||
|
||||
}//end printCodeComparisonBlock()
|
||||
|
||||
|
||||
}//end class
|
Reference in New Issue
Block a user