From 7b0931fb5bcc5fdf75bd0b8202bd992c388997e7 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Tue, 17 Jun 2014 09:32:43 +0200 Subject: PSR-2 formatting --- composer.json | 68 ++++---- src/HTML5.php | 18 +- src/HTML5/Elements.php | 6 +- src/HTML5/Parser/CharacterReference.php | 2 +- src/HTML5/Parser/DOMTreeBuilder.php | 34 ++-- src/HTML5/Parser/EventHandler.php | 6 +- src/HTML5/Parser/InputStream.php | 2 +- src/HTML5/Parser/Scanner.php | 8 +- src/HTML5/Parser/StringInputStream.php | 16 +- src/HTML5/Parser/Tokenizer.php | 222 ++++++++++++------------- src/HTML5/Parser/TreeBuildingRules.php | 2 +- src/HTML5/Parser/UTF8Utils.php | 4 +- src/HTML5/Serializer/OutputRules.php | 12 +- src/HTML5/Serializer/Traverser.php | 6 +- test/HTML5/Html5Test.php | 8 +- test/HTML5/Parser/DOMTreeBuilderTest.php | 4 +- test/HTML5/Parser/EventStack.php | 8 +- test/HTML5/Parser/InstructionProcessorMock.php | 4 +- test/HTML5/Parser/StringInputStreamTest.php | 2 +- test/HTML5/Parser/TokenizerTest.php | 222 ++++++++++++------------- test/HTML5/Serializer/OutputRulesTest.php | 16 +- 21 files changed, 335 insertions(+), 335 deletions(-) diff --git a/composer.json b/composer.json index 549ef28..00b868f 100644 --- a/composer.json +++ b/composer.json @@ -1,38 +1,38 @@ { - "name": "masterminds/html5", - "description": "An HTML5 parser and serializer.", - "type": "library", - "homepage": "http://masterminds.github.io/html5-php", - "license": "MIT", - "keywords": ["xml", "html", "html5", "dom", "parser", "serializer", "querypath"], - "authors": [ - { - "name": "Matt Butcher", - "email": "technosophos@gmail.com" + "name": "masterminds/html5", + "description": "An HTML5 parser and serializer.", + "type": "library", + "homepage": "http://masterminds.github.io/html5-php", + "license": "MIT", + "keywords": ["xml", "html", "html5", "dom", "parser", "serializer", "querypath"], + "authors": [ + { + "name": "Matt Butcher", + "email": "technosophos@gmail.com" + }, + { + "name": "Matt Farina", + "email": "matt@mattfarina.com" + } + ], + "require" : { + "ext-libxml" : "*", + "php" : ">=5.3.0" }, - { - "name": "Matt Farina", - "email": "matt@mattfarina.com" - } - ], - "require" : { - "ext-libxml" : "*", - "php" : ">=5.3.0" - }, - "require-dev": { - "satooshi/php-coveralls": "0.6.*", - "phpunit/phpunit" : "4.*", - "phpdocumentor/phpdocumentor": "2.*" - }, - "autoload": { - "psr-4": {"Masterminds\\": "src"} - }, - "autoload-dev": { - "psr-4": {"Masterminds\\HTML5\\Tests\\": "test/HTML5"} - }, - "extra": { - "branch-alias": { - "dev-master": "2.0-dev" + "require-dev": { + "satooshi/php-coveralls": "0.6.*", + "phpunit/phpunit" : "4.*", + "phpdocumentor/phpdocumentor": "2.*" + }, + "autoload": { + "psr-4": {"Masterminds\\": "src"} + }, + "autoload-dev": { + "psr-4": {"Masterminds\\HTML5\\Tests\\": "test/HTML5"} + }, + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } } - } } diff --git a/src/HTML5.php b/src/HTML5.php index 959c3d2..16187df 100644 --- a/src/HTML5.php +++ b/src/HTML5.php @@ -26,7 +26,7 @@ class HTML5 */ private $options = array( // If the serializer should encode all entities. - 'encode_entities' => FALSE + 'encode_entities' => false ); private $errors = array(); @@ -158,7 +158,7 @@ class HTML5 public function parse(\Masterminds\HTML5\Parser\InputStream $input) { $this->errors = array(); - $events = new DOMTreeBuilder(FALSE, $this->options); + $events = new DOMTreeBuilder(false, $this->options); $scanner = new Scanner($input); $parser = new Tokenizer($scanner, $events); @@ -181,7 +181,7 @@ class HTML5 */ public function parseFragment(\Masterminds\HTML5\Parser\InputStream $input) { - $events = new DOMTreeBuilder(TRUE, $this->options); + $events = new DOMTreeBuilder(true, $this->options); $scanner = new Scanner($input); $parser = new Tokenizer($scanner, $events); @@ -200,15 +200,15 @@ class HTML5 * @param array $options * Configuration options when serializing the DOM. These include: * - encode_entities: Text written to the output is escaped by default and not all - * entities are encoded. If this is set to TRUE all entities will be encoded. - * Defaults to FALSE. + * entities are encoded. If this is set to true all entities will be encoded. + * Defaults to false. */ public function save($dom, $file, $options = array()) { - $close = TRUE; + $close = true; if (is_resource($file)) { $stream = $file; - $close = FALSE; + $close = false; } else { $stream = fopen($file, 'w'); } @@ -231,8 +231,8 @@ class HTML5 * @param array $options * Configuration options when serializing the DOM. These include: * - encode_entities: Text written to the output is escaped by default and not all - * entities are encoded. If this is set to TRUE all entities will be encoded. - * Defaults to FALSE. + * entities are encoded. If this is set to true all entities will be encoded. + * Defaults to false. * * @return string A HTML5 documented generated from the DOM. */ diff --git a/src/HTML5/Elements.php b/src/HTML5/Elements.php index 2b9ba63..819ce0e 100644 --- a/src/HTML5/Elements.php +++ b/src/HTML5/Elements.php @@ -476,12 +476,12 @@ class Elements * The element name. * @param int $mask * One of the constants on this class. - * @return boolean TRUE if the element matches the mask, FALSE otherwise. + * @return boolean true if the element matches the mask, false otherwise. */ public static function isA($name, $mask) { if (! static::isElement($name)) { - return FALSE; + return false; } return (static::element($name) & $mask) == $mask; @@ -566,7 +566,7 @@ class Elements return static::$mathml[$name]; } - return FALSE; + return false; } /** diff --git a/src/HTML5/Parser/CharacterReference.php b/src/HTML5/Parser/CharacterReference.php index 24cc687..c1617e7 100644 --- a/src/HTML5/Parser/CharacterReference.php +++ b/src/HTML5/Parser/CharacterReference.php @@ -30,7 +30,7 @@ class CharacterReference public static function lookupName($name) { // Do we really want to return NULL here? or FFFD - return isset(Entities::$byName[$name]) ? Entities::$byName[$name] : NULL; + return isset(Entities::$byName[$name]) ? Entities::$byName[$name] : null; } /** diff --git a/src/HTML5/Parser/DOMTreeBuilder.php b/src/HTML5/Parser/DOMTreeBuilder.php index a1723de..731d1d8 100644 --- a/src/HTML5/Parser/DOMTreeBuilder.php +++ b/src/HTML5/Parser/DOMTreeBuilder.php @@ -143,9 +143,9 @@ class DOMTreeBuilder implements EventHandler * Any document that is missing the * DT will be considered to be in quirks mode. */ - protected $quirks = TRUE; + protected $quirks = true; - public function __construct($isFragment = FALSE, array $options = array()) + public function __construct($isFragment = false, array $options = array()) { $this->options = $options; @@ -155,7 +155,7 @@ class DOMTreeBuilder implements EventHandler // documents, and attempting to up-convert any older DTDs to HTML5. $dt = $impl->createDocumentType('html'); // $this->doc = \DOMImplementation::createDocument(NULL, 'html', $dt); - $this->doc = $impl->createDocument(NULL, NULL, $dt); + $this->doc = $impl->createDocument(null, null, $dt); $this->doc->errors = array(); $this->current = $this->doc; // ->documentElement; @@ -210,7 +210,7 @@ class DOMTreeBuilder implements EventHandler $this->processor = $proc; } - public function doctype($name, $idType = 0, $id = NULL, $quirks = FALSE) + public function doctype($name, $idType = 0, $id = null, $quirks = false) { // This is used solely for setting quirks mode. Currently we don't // try to preserve the inbound DT. We convert it to HTML5. @@ -232,7 +232,7 @@ class DOMTreeBuilder implements EventHandler * - XLink, MathML and SVG namespace handling * - Omission rules: 8.1.2.4 Optional tags */ - public function startTag($name, $attributes = array(), $selfClosing = FALSE) + public function startTag($name, $attributes = array(), $selfClosing = false) { // fprintf(STDOUT, $name); $lname = $this->normalizeTagName($name); @@ -244,7 +244,7 @@ class DOMTreeBuilder implements EventHandler // Set quirks mode if we're at IM_INITIAL with no doctype. if ($this->insertMode == static::IM_INITIAL) { - $this->quirks = TRUE; + $this->quirks = true; $this->parseError("No DOCTYPE specified."); } @@ -301,7 +301,7 @@ class DOMTreeBuilder implements EventHandler $pushes ++; } if (isset($this->options["xmlNamespaces"]) && $this->options["xmlNamespaces"]) { - // when xmlNamespaces is TRUE a and we found a 'xmlns' or 'xmlns:*' attribute, we should add a new item to the $nsStack + // when xmlNamespaces is true a and we found a 'xmlns' or 'xmlns:*' attribute, we should add a new item to the $nsStack foreach ($attributes as $aName => $aVal) { if ($aName === 'xmlns') { array_unshift($this->nsStack, array( @@ -364,7 +364,7 @@ class DOMTreeBuilder implements EventHandler // This is necessary on a non-DTD schema, like HTML5. if ($aName == 'id') { - $ele->setIdAttribute('id', TRUE); + $ele->setIdAttribute('id', true); } } @@ -510,7 +510,7 @@ class DOMTreeBuilder implements EventHandler $this->current->appendChild($node); } - public function processingInstruction($name, $data = NULL) + public function processingInstruction($name, $data = null) { // XXX: Ignore initial XML declaration, per the spec. if ($this->insertMode == static::IM_INITIAL && 'xml' == strtolower($name)) { @@ -550,7 +550,7 @@ class DOMTreeBuilder implements EventHandler protected function normalizeTagName($name) { /* - * Section 2.9 suggests that we should not do this. if (strpos($name, ':') !== FALSE) { // We know from the grammar that there must be at least one other // char besides :, since : is not a legal tag start. $parts = explode(':', $name); return array_pop($parts); } + * Section 2.9 suggests that we should not do this. if (strpos($name, ':') !== false) { // We know from the grammar that there must be at least one other // char besides :, since : is not a legal tag start. $parts = explode(':', $name); return array_pop($parts); } */ return $name; } @@ -568,38 +568,38 @@ class DOMTreeBuilder implements EventHandler $working = $this->current; do { if ($working->nodeType != XML_ELEMENT_NODE) { - return FALSE; + return false; } if ($working->tagName == $tag) { $this->current = $working->parentNode; - return TRUE; + return true; } } while ($working = $working->parentNode); - return FALSE; + return false; } /** * Checks if the given tagname is an ancestor of the present candidate. * * If $this->current or anything above $this->current matches the given tag - * name, this returns TRUE. + * name, this returns true. */ protected function isAncestor($tagname) { $candidate = $this->current; while ($candidate->nodeType === XML_ELEMENT_NODE) { if ($candidate->tagName == $tagname) { - return TRUE; + return true; } $candidate = $candidate->parentNode; } - return FALSE; + return false; } /** - * Returns TRUE if the immediate parent element is of the given tagname. + * Returns true if the immediate parent element is of the given tagname. */ protected function isParent($tagname) { diff --git a/src/HTML5/Parser/EventHandler.php b/src/HTML5/Parser/EventHandler.php index ef80909..2d55347 100644 --- a/src/HTML5/Parser/EventHandler.php +++ b/src/HTML5/Parser/EventHandler.php @@ -40,7 +40,7 @@ interface EventHandler * @param boolean $quirks * Indicates whether the builder should enter quirks mode. */ - public function doctype($name, $idType = 0, $id = NULL, $quirks = FALSE); + public function doctype($name, $idType = 0, $id = null, $quirks = false); /** * A start tag. @@ -71,7 +71,7 @@ interface EventHandler * An indicator of whether or not this tag is self-closing () * @return numeric One of the Tokenizer::TEXTMODE_* constants. */ - public function startTag($name, $attributes = array(), $selfClosing = FALSE); + public function startTag($name, $attributes = array(), $selfClosing = false); /** * An end-tag. @@ -118,5 +118,5 @@ interface EventHandler * @param string $data * The unparsed data. */ - public function processingInstruction($name, $data = NULL); + public function processingInstruction($name, $data = null); } diff --git a/src/HTML5/Parser/InputStream.php b/src/HTML5/Parser/InputStream.php index 7113d6c..0bdc803 100644 --- a/src/HTML5/Parser/InputStream.php +++ b/src/HTML5/Parser/InputStream.php @@ -51,7 +51,7 @@ interface InputStream extends \Iterator * Bytes to match. * @param int $max * Maximum number of bytes to scan. - * @return mixed Index or FALSE if no match is found. You should use strong + * @return mixed Index or false if no match is found. You should use strong * equality when checking the result, since index could be 0. */ public function charsUntil($bytes, $max = null); diff --git a/src/HTML5/Parser/Scanner.php b/src/HTML5/Parser/Scanner.php index a262004..a92c608 100644 --- a/src/HTML5/Parser/Scanner.php +++ b/src/HTML5/Parser/Scanner.php @@ -17,8 +17,8 @@ class Scanner protected $is; - // Flipping this to TRUE will give minisculely more debugging info. - public $debug = FALSE; + // Flipping this to true will give minisculely more debugging info. + public $debug = false; /** * Create a new Scanner. @@ -67,7 +67,7 @@ class Scanner return $this->is->current(); } - return FALSE; + return false; } /** @@ -83,7 +83,7 @@ class Scanner return $this->is->current(); } - return FALSE; + return false; } /** diff --git a/src/HTML5/Parser/StringInputStream.php b/src/HTML5/Parser/StringInputStream.php index 9648bce..4cac3c2 100644 --- a/src/HTML5/Parser/StringInputStream.php +++ b/src/HTML5/Parser/StringInputStream.php @@ -152,7 +152,7 @@ class StringInputStream implements InputStream // However, for here we want the length up until the next byte to be // processed, so add one to the current byte ($this->char). - if ($lastLine !== FALSE) { + if ($lastLine !== false) { $findLengthOf = substr($this->data, $lastLine + 1, $this->char - 1 - $lastLine); } else { // After a newline. @@ -207,10 +207,10 @@ class StringInputStream implements InputStream public function valid() { if ($this->char < $this->EOF) { - return TRUE; + return true; } - return FALSE; + return false; } /** @@ -233,7 +233,7 @@ class StringInputStream implements InputStream return $data; } - return ''; // FALSE; + return ''; // false; } /** @@ -248,13 +248,13 @@ class StringInputStream implements InputStream * Bytes to match. * @param int $max * Maximum number of bytes to scan. - * @return mixed Index or FALSE if no match is found. You should use strong + * @return mixed Index or false if no match is found. You should use strong * equality when checking the result, since index could be 0. */ public function charsUntil($bytes, $max = null) { if ($this->char >= $this->EOF) { - return FALSE; + return false; } if ($max === 0 || $max) { @@ -285,7 +285,7 @@ class StringInputStream implements InputStream public function charsWhile($bytes, $max = null) { if ($this->char >= $this->EOF) { - return FALSE; + return false; } if ($max === 0 || $max) { @@ -321,7 +321,7 @@ class StringInputStream implements InputStream return $this->data[$this->char + 1]; } - return FALSE; + return false; } public function key() diff --git a/src/HTML5/Parser/Tokenizer.php b/src/HTML5/Parser/Tokenizer.php index 0db9ee1..8f34494 100644 --- a/src/HTML5/Parser/Tokenizer.php +++ b/src/HTML5/Parser/Tokenizer.php @@ -38,10 +38,10 @@ class Tokenizer protected $text = ''; // When this goes to false, the parser stops. - protected $carryOn = TRUE; + protected $carryOn = true; protected $textMode = 0; // TEXTMODE_NORMAL; - protected $untilTag = NULL; + protected $untilTag = null; const WHITE = "\t\n\f "; @@ -106,7 +106,7 @@ class Tokenizer * The tag that should stop RAW or RCDATA mode. Normal mode does not * use this indicator. */ - public function setTextMode($textmode, $untilTag = NULL) + public function setTextMode($textmode, $untilTag = null) { $this->textMode = $textmode & (Elements::TEXT_RAW | Elements::TEXT_RCDATA); $this->untilTag = $untilTag; @@ -139,8 +139,8 @@ class Tokenizer */ protected function characterData() { - if ($this->scanner->current() === FALSE) { - return FALSE; + if ($this->scanner->current() === false) { + return false; } switch ($this->textMode) { case Elements::TEXT_RAW: @@ -150,7 +150,7 @@ class Tokenizer default: $tok = $this->scanner->current(); if (strspn($tok, "<&")) { - return FALSE; + return false; } return $this->text(); } @@ -164,17 +164,17 @@ class Tokenizer $tok = $this->scanner->current(); // This should never happen... - if ($tok === FALSE) { - return FALSE; + if ($tok === false) { + return false; } // Null if ($tok === "\00") { - $this->parseError("Received NULL character."); + $this->parseError("Received null character."); } // fprintf(STDOUT, "Writing '%s'", $tok); $this->buffer($tok); $this->scanner->next(); - return TRUE; + return true; } /** @@ -203,7 +203,7 @@ class Tokenizer $sequence = 'untilTag . '>'; $txt = ''; $tok = $this->scanner->current(); - while ($tok !== FALSE && ! ($tok == '<' && ($this->sequenceMatches($sequence) || $this->sequenceMatches(strtoupper($sequence))))) { + while ($tok !== false && ! ($tok == '<' && ($this->sequenceMatches($sequence) || $this->sequenceMatches(strtoupper($sequence))))) { if ($tok == '&') { $txt .= $this->decodeCharacterReference(); $tok = $this->scanner->current(); @@ -222,14 +222,14 @@ class Tokenizer */ protected function eof() { - if ($this->scanner->current() === FALSE) { + if ($this->scanner->current() === false) { // fprintf(STDOUT, "EOF"); $this->flushBuffer(); $this->events->eof(); - $this->carryOn = FALSE; - return TRUE; + $this->carryOn = false; + return true; } - return FALSE; + return false; } /** @@ -243,11 +243,11 @@ class Tokenizer protected function characterReference() { $ref = $this->decodeCharacterReference(); - if ($ref !== FALSE) { + if ($ref !== false) { $this->buffer($ref); - return TRUE; + return true; } - return FALSE; + return false; } /** @@ -258,7 +258,7 @@ class Tokenizer protected function tagOpen() { if ($this->scanner->current() != '<') { - return FALSE; + return false; } // Any buffered text data can go out now. @@ -277,7 +277,7 @@ class Tokenizer protected function markupDeclaration() { if ($this->scanner->current() != '!') { - return FALSE; + return false; } $tok = $this->scanner->next(); @@ -300,7 +300,7 @@ class Tokenizer // FINISH $this->parseError("Expected b'); - $this->assertEquals(4, $events->depth(), "Events: " . print_r($events, TRUE)); + $this->assertEquals(4, $events->depth(), "Events: " . print_r($events, true)); $this->assertEventEquals('text', 'a', $events->get(0)); $this->assertEventEquals('comment', 'test', $events->get(1)); $this->assertEventEquals('text', 'b', $events->get(2)); $events = $this->parse('a&b'); - $this->assertEquals(2, $events->depth(), "Events: " . print_r($events, TRUE)); + $this->assertEquals(2, $events->depth(), "Events: " . print_r($events, true)); $this->assertEventEquals('text', 'a&b', $events->get(0)); } // ================================================================ // Utility functions. // ================================================================ - protected function createTokenizer($string, $debug = FALSE) + protected function createTokenizer($string, $debug = false) { $eventHandler = new EventStack(); $stream = new StringInputStream($string); @@ -943,7 +943,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase ); } - public function parse($string, $debug = FALSE) + public function parse($string, $debug = false) { list ($tok, $events) = $this->createTokenizer($string, $debug); $tok->parse(); diff --git a/test/HTML5/Serializer/OutputRulesTest.php b/test/HTML5/Serializer/OutputRulesTest.php index bf200e3..a54a754 100644 --- a/test/HTML5/Serializer/OutputRulesTest.php +++ b/test/HTML5/Serializer/OutputRulesTest.php @@ -363,44 +363,44 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase { return array( array( - FALSE, + false, '&\'<>"', '&\'<>"', '&'<>"' ), array( - FALSE, + false, 'This + is. a < test', 'This + is. a < test', 'This + is. a < test' ), array( - FALSE, + false, '.+#', '.+#', '.+#' ), array( - TRUE, + true, '.+#\'', '.+#\'', '.+#'' ), array( - TRUE, + true, '&".<', '&".<', '&".<' ), array( - TRUE, + true, '&\'<>"', '&\'<>"', '&'<>"' ), array( - TRUE, + true, "\xc2\xa0\"'", ' "\'', ' "'' @@ -420,7 +420,7 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $this->assertEquals($expected, $m->invoke($o, $test, $isAttribute)); list ($o, $s) = $this->getOutputRules(array( - 'encode_entities' => TRUE + 'encode_entities' => true )); $m = $this->getProtectedMethod('enc'); $this->assertEquals($expectedEncoded, $m->invoke($o, $test, $isAttribute)); -- cgit v1.2.3