diff options
author | Asmir Mustafic <[email protected]> | 2014-06-17 09:32:43 +0200 |
---|---|---|
committer | Asmir Mustafic <[email protected]> | 2014-06-17 09:32:43 +0200 |
commit | 7b0931fb5bcc5fdf75bd0b8202bd992c388997e7 (patch) | |
tree | 38b1cd87d19d244a4e9a258f6ee51be7d3a9e43c | |
parent | 44f07f1f7ec5b995a5279eb4f61ea0dbb0cb616e (diff) |
PSR-2 formatting
-rw-r--r-- | composer.json | 68 | ||||
-rw-r--r-- | src/HTML5.php | 18 | ||||
-rw-r--r-- | src/HTML5/Elements.php | 6 | ||||
-rw-r--r-- | src/HTML5/Parser/CharacterReference.php | 2 | ||||
-rw-r--r-- | src/HTML5/Parser/DOMTreeBuilder.php | 34 | ||||
-rw-r--r-- | src/HTML5/Parser/EventHandler.php | 6 | ||||
-rw-r--r-- | src/HTML5/Parser/InputStream.php | 2 | ||||
-rw-r--r-- | src/HTML5/Parser/Scanner.php | 8 | ||||
-rw-r--r-- | src/HTML5/Parser/StringInputStream.php | 16 | ||||
-rw-r--r-- | src/HTML5/Parser/Tokenizer.php | 222 | ||||
-rw-r--r-- | src/HTML5/Parser/TreeBuildingRules.php | 2 | ||||
-rw-r--r-- | src/HTML5/Parser/UTF8Utils.php | 4 | ||||
-rw-r--r-- | src/HTML5/Serializer/OutputRules.php | 12 | ||||
-rw-r--r-- | src/HTML5/Serializer/Traverser.php | 6 | ||||
-rw-r--r-- | test/HTML5/Html5Test.php | 8 | ||||
-rw-r--r-- | test/HTML5/Parser/DOMTreeBuilderTest.php | 4 | ||||
-rw-r--r-- | test/HTML5/Parser/EventStack.php | 8 | ||||
-rw-r--r-- | test/HTML5/Parser/InstructionProcessorMock.php | 4 | ||||
-rw-r--r-- | test/HTML5/Parser/StringInputStreamTest.php | 2 | ||||
-rw-r--r-- | test/HTML5/Parser/TokenizerTest.php | 222 | ||||
-rw-r--r-- | 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": "[email protected]" + "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": "[email protected]" + }, + { + "name": "Matt Farina", + "email": "[email protected]" + } + ], + "require" : { + "ext-libxml" : "*", + "php" : ">=5.3.0" }, - { - "name": "Matt Farina", - "email": "[email protected]" - } - ], - "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 (<foo/>) * @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 = '</' . $this->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 <!--, <![CDATA[, or <!DOCTYPE. Got <!%s", $tok); $this->bogusComment('<!'); - return TRUE; + return true; } /** @@ -310,7 +310,7 @@ class Tokenizer protected function endTag() { if ($this->scanner->current() != '/') { - return FALSE; + return false; } $tok = $this->scanner->next(); @@ -320,8 +320,8 @@ class Tokenizer // -> parse error if (! ctype_alpha($tok)) { $this->parseError("Expected tag name, got '%s'", $tok); - if ($tok == "\0" || $tok === FALSE) { - return FALSE; + if ($tok == "\0" || $tok === false) { + return false; } return $this->bogusComment('</'); } @@ -338,7 +338,7 @@ class Tokenizer $this->events->endTag($name); $this->scanner->next(); - return TRUE; + return true; } /** @@ -349,13 +349,13 @@ class Tokenizer { $tok = $this->scanner->current(); if (! ctype_alpha($tok)) { - return FALSE; + return false; } // We know this is at least one char. $name = strtolower($this->scanner->charsWhile(":0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); $attributes = array(); - $selfClose = FALSE; + $selfClose = false; // Handle attribute parse exceptions here so that we can // react by trying to build a sensible parse tree. @@ -365,7 +365,7 @@ class Tokenizer $this->attribute($attributes); } while (! $this->isTagEnd($selfClose)); } catch (ParseError $e) { - $selfClose = FALSE; + $selfClose = false; } $mode = $this->events->startTag($name, $attributes, $selfClose); @@ -379,7 +379,7 @@ class Tokenizer $this->scanner->next(); - return TRUE; + return true; } /** @@ -392,28 +392,28 @@ class Tokenizer $this->scanner->next(); $this->scanner->whitespace(); if ($this->scanner->current() == '>') { - $selfClose = TRUE; - return TRUE; + $selfClose = true; + return true; } - if ($this->scanner->current() === FALSE) { + if ($this->scanner->current() === false) { $this->parseError("Unexpected EOF inside of tag."); - return TRUE; + return true; } // Basically, we skip the / token and go on. // See 8.2.4.43. $this->parseError("Unexpected '%s' inside of a tag.", $this->scanner->current()); - return FALSE; + return false; } if ($this->scanner->current() == '>') { - return TRUE; + return true; } - if ($this->scanner->current() === FALSE) { + if ($this->scanner->current() === false) { $this->parseError("Unexpected EOF inside of tag."); - return TRUE; + return true; } - return FALSE; + return false; } /** @@ -422,8 +422,8 @@ class Tokenizer protected function attribute(&$attributes) { $tok = $this->scanner->current(); - if ($tok == '/' || $tok == '>' || $tok === FALSE) { - return FALSE; + if ($tok == '/' || $tok == '>' || $tok === false) { + return false; } if ($tok == '<') { @@ -444,7 +444,7 @@ class Tokenizer $this->scanner->next(); } - $isValidAttribute = TRUE; + $isValidAttribute = true; // Attribute names can contain most Unicode characters for HTML5. // But method "DOMElement::setAttribute" is throwing exception // because of it's own internal restriction so these have to be filtered. @@ -452,7 +452,7 @@ class Tokenizer // and http://www.w3.org/TR/2011/WD-html5-20110525/syntax.html#syntax-attribute-name if (preg_match("/[\x1-\x2C\\/\x3B-\x40\x5B-\x5E\x60\x7B-\x7F]/u", $name)) { $this->parseError("Unexpected characters in attribute name: %s", $name); - $isValidAttribute = FALSE; + $isValidAttribute = false; } // There is no limitation for 1st character in HTML5. // But method "DOMElement::setAttribute" is throwing exception for the // characters below so they have to be filtered. @@ -461,7 +461,7 @@ class Tokenizer else if (preg_match("/^[0-9.-]/u", $name)) { $this->parseError("Unexpected character at the begining of attribute name: %s", $name); - $isValidAttribute = FALSE; + $isValidAttribute = false; } // 8.1.2.3 $this->scanner->whitespace(); @@ -470,7 +470,7 @@ class Tokenizer if ($isValidAttribute) { $attributes[$name] = $val; } - return TRUE; + return true; } /** @@ -480,7 +480,7 @@ class Tokenizer protected function attributeValue() { if ($this->scanner->current() != '=') { - return NULL; + return null; } $this->scanner->next(); // 8.1.2.3 @@ -493,7 +493,7 @@ class Tokenizer case " ": case "\t": // Whitespace here indicates an empty value. - return NULL; + return null; case '"': case "'": $this->scanner->next(); @@ -501,7 +501,7 @@ class Tokenizer case '>': // case '/': // 8.2.4.37 seems to allow foo=/ as a valid attr. $this->parseError("Expected attribute value, got tag end."); - return NULL; + return null; case '=': case '`': $this->parseError("Expecting quotes, got %s.", $tok); @@ -525,9 +525,9 @@ class Tokenizer $stoplist = "\f" . $quote; $val = ''; $tok = $this->scanner->current(); - while (strspn($tok, $stoplist) == 0 && $tok !== FALSE) { + while (strspn($tok, $stoplist) == 0 && $tok !== false) { if ($tok == '&') { - $val .= $this->decodeCharacterReference(TRUE); + $val .= $this->decodeCharacterReference(true); $tok = $this->scanner->current(); } else { $val .= $tok; @@ -543,9 +543,9 @@ class Tokenizer $stoplist = "\t\n\f >"; $val = ''; $tok = $this->scanner->current(); - while (strspn($tok, $stoplist) == 0 && $tok !== FALSE) { + while (strspn($tok, $stoplist) == 0 && $tok !== false) { if ($tok == '&') { - $val .= $this->decodeCharacterReference(TRUE); + $val .= $this->decodeCharacterReference(true); $tok = $this->scanner->current(); } else { if (strspn($tok, "\"'<=`") > 0) { @@ -582,13 +582,13 @@ class Tokenizer do { $comment .= $tok; $tok = $this->scanner->next(); - } while ($tok !== FALSE && $tok != '>'); + } while ($tok !== false && $tok != '>'); $this->flushBuffer(); $this->events->comment($comment . $tok); $this->scanner->next(); - return TRUE; + return true; } /** @@ -607,7 +607,7 @@ class Tokenizer $this->parseError("Expected comment data, got '>'"); $this->events->comment(''); $this->scanner->next(); - return TRUE; + return true; } // Replace NULL with the replacement char. @@ -621,7 +621,7 @@ class Tokenizer $this->events->comment($comment); $this->scanner->next(); - return TRUE; + return true; } /** @@ -630,25 +630,25 @@ class Tokenizer protected function isCommentEnd() { // EOF - if ($this->scanner->current() === FALSE) { + if ($this->scanner->current() === false) { // Hit the end. $this->parseError("Unexpected EOF in a comment."); - return TRUE; + return true; } // If it doesn't start with -, not the end. if ($this->scanner->current() != '-') { - return FALSE; + return false; } // Advance one, and test for '->' if ($this->scanner->next() == '-' && $this->scanner->peek() == '>') { $this->scanner->next(); // Consume the last '>' - return TRUE; + return true; } // Unread '-'; $this->scanner->unconsume(1); - return FALSE; + return false; } /** @@ -662,7 +662,7 @@ class Tokenizer protected function doctype() { if (strcasecmp($this->scanner->current(), 'D')) { - return FALSE; + return false; } // Check that string is DOCTYPE. $chars = $this->scanner->charsWhile("DOCTYPEdoctype"); @@ -675,8 +675,8 @@ class Tokenizer $tok = $this->scanner->current(); // EOF: die. - if ($tok === FALSE) { - $this->events->doctype('html5', EventHandler::DOCTYPE_NONE, '', TRUE); + if ($tok === false) { + $this->events->doctype('html5', EventHandler::DOCTYPE_NONE, '', true); return $this->eof(); } @@ -684,7 +684,7 @@ class Tokenizer // NULL char: convert. if ($tok === "\0") { - $this->parseError("Unexpected NULL character in DOCTYPE."); + $this->parseError("Unexpected null character in DOCTYPE."); $doctypeName .= UTF8::FFFD; $tok = $this->scanner->next(); } @@ -696,11 +696,11 @@ class Tokenizer $tok = $this->scanner->current(); - // If FALSE, emit a parse error, DOCTYPE, and return. - if ($tok === FALSE) { + // If false, emit a parse error, DOCTYPE, and return. + if ($tok === false) { $this->parseError('Unexpected EOF in DOCTYPE declaration.'); - $this->events->doctype($doctypeName, EventHandler::DOCTYPE_NONE, NULL, TRUE); - return TRUE; + $this->events->doctype($doctypeName, EventHandler::DOCTYPE_NONE, null, true); + return true; } // Short DOCTYPE, like <!DOCTYPE html> @@ -708,13 +708,13 @@ class Tokenizer // DOCTYPE without a name. if (strlen($doctypeName) == 0) { $this->parseError("Expected a DOCTYPE name. Got nothing."); - $this->events->doctype($doctypeName, 0, NULL, TRUE); + $this->events->doctype($doctypeName, 0, null, true); $this->scanner->next(); - return TRUE; + return true; } $this->events->doctype($doctypeName); $this->scanner->next(); - return TRUE; + return true; } $this->scanner->whitespace(); @@ -727,33 +727,33 @@ class Tokenizer // Get the sys ID. $type = $pub == 'PUBLIC' ? EventHandler::DOCTYPE_PUBLIC : EventHandler::DOCTYPE_SYSTEM; $id = $this->quotedString("\0>"); - if ($id === FALSE) { - $this->events->doctype($doctypeName, $type, $pub, FALSE); - return FALSE; + if ($id === false) { + $this->events->doctype($doctypeName, $type, $pub, false); + return false; } // Premature EOF. - if ($this->scanner->current() === FALSE) { + if ($this->scanner->current() === false) { $this->parseError("Unexpected EOF in DOCTYPE"); - $this->events->doctype($doctypeName, $type, $id, TRUE); - return TRUE; + $this->events->doctype($doctypeName, $type, $id, true); + return true; } // Well-formed complete DOCTYPE. $this->scanner->whitespace(); if ($this->scanner->current() == '>') { - $this->events->doctype($doctypeName, $type, $id, FALSE); + $this->events->doctype($doctypeName, $type, $id, false); $this->scanner->next(); - return TRUE; + return true; } // If we get here, we have <!DOCTYPE foo PUBLIC "bar" SOME_JUNK - // Throw away the junk, parse error, quirks mode, return TRUE. + // Throw away the junk, parse error, quirks mode, return true. $this->scanner->charsUntil(">"); $this->parseError("Malformed DOCTYPE."); - $this->events->doctype($doctypeName, $type, $id, TRUE); + $this->events->doctype($doctypeName, $type, $id, true); $this->scanner->next(); - return TRUE; + return true; } // Else it's a bogus DOCTYPE. @@ -761,9 +761,9 @@ class Tokenizer $this->scanner->charsUntil('>'); $this->parseError("Expected PUBLIC or SYSTEM. Got %s.", $pub); - $this->events->doctype($doctypeName, 0, NULL, TRUE); + $this->events->doctype($doctypeName, 0, null, true); $this->scanner->next(); - return TRUE; + return true; } /** @@ -788,7 +788,7 @@ class Tokenizer } return $ret; } - return FALSE; + return false; } /** @@ -797,7 +797,7 @@ class Tokenizer protected function cdataSection() { if ($this->scanner->current() != '[') { - return FALSE; + return false; } $cdata = ''; $this->scanner->next(); @@ -810,10 +810,10 @@ class Tokenizer $tok = $this->scanner->next(); do { - if ($tok === FALSE) { + if ($tok === false) { $this->parseError('Unexpected EOF inside CDATA.'); $this->bogusComment('<![CDATA[' . $cdata); - return TRUE; + return true; } $cdata .= $tok; $tok = $this->scanner->next(); @@ -823,7 +823,7 @@ class Tokenizer $this->scanner->consume(3); $this->events->cdata($cdata); - return TRUE; + return true; } // ================================================================ @@ -840,7 +840,7 @@ class Tokenizer protected function processingInstruction() { if ($this->scanner->current() != '?') { - return FALSE; + return false; } $tok = $this->scanner->next(); @@ -848,10 +848,10 @@ class Tokenizer $white = strlen($this->scanner->whitespace()); // If not a PI, send to bogusComment. - if (strlen($procName) == 0 || $white == 0 || $this->scanner->current() == FALSE) { + if (strlen($procName) == 0 || $white == 0 || $this->scanner->current() == false) { $this->parseError("Expected processing instruction name, got $tok"); $this->bogusComment('<?' . $tok . $procName); - return TRUE; + return true; } $data = ''; @@ -860,17 +860,17 @@ class Tokenizer $data .= $this->scanner->current(); $tok = $this->scanner->next(); - if ($tok === FALSE) { + if ($tok === false) { $this->parseError("Unexpected EOF in processing instruction."); $this->events->processingInstruction($procName, $data); - return TRUE; + return true; } } $this->scanner->next(); // > $this->scanner->next(); // Next token. $this->events->processingInstruction($procName, $data); - return TRUE; + return true; } // ================================================================ @@ -887,7 +887,7 @@ class Tokenizer // Optimization for reading larger blocks faster. $first = substr($sequence, 0, 1); - while ($this->scanner->current() !== FALSE) { + while ($this->scanner->current() !== false) { $buffer .= $this->scanner->charsUntil($first); // Stop as soon as we hit the stopping condition. @@ -907,10 +907,10 @@ class Tokenizer * Check if upcomming chars match the given sequence. * * This will read the stream for the $sequence. If it's - * found, this will return TRUE. If not, return FALSE. + * found, this will return true. If not, return false. * Since this unconsumes any chars it reads, the caller * will still need to read the next sequence, even if - * this returns TRUE. + * this returns true. * * Example: $this->sequenceMatches('</script>') will * see if the input stream is at the start of a @@ -924,9 +924,9 @@ class Tokenizer $buffer .= $this->scanner->current(); // EOF. Rewind and let the caller handle it. - if ($this->scanner->current() === FALSE) { + if ($this->scanner->current() === false) { $this->scanner->unconsume($i); - return FALSE; + return false; } $this->scanner->next(); } @@ -964,7 +964,7 @@ class Tokenizer /** * Emit a parse error. * - * A parse error always returns FALSE because it never consumes any + * A parse error always returns false because it never consumes any * characters. */ protected function parseError($msg) @@ -979,25 +979,25 @@ class Tokenizer $line = $this->scanner->currentLine(); $col = $this->scanner->columnOffset(); $this->events->parseError($msg, $line, $col); - return FALSE; + return false; } /** * Decode a character reference and return the string. * - * Returns FALSE if the entity could not be found. If $inAttribute is set - * to TRUE, a bare & will be returned as-is. + * Returns false if the entity could not be found. If $inAttribute is set + * to true, a bare & will be returned as-is. * * @param boolean $inAttribute - * Set to TRUE if the text is inside of an attribute value. - * FALSE otherwise. + * Set to true if the text is inside of an attribute value. + * false otherwise. */ - protected function decodeCharacterReference($inAttribute = FALSE) + protected function decodeCharacterReference($inAttribute = false) { // If it fails this, it's definitely not an entity. if ($this->scanner->current() != '&') { - return FALSE; + return false; } // Next char after &. @@ -1005,7 +1005,7 @@ class Tokenizer $entity = ''; $start = $this->scanner->position(); - if ($tok == FALSE) { + if ($tok == false) { return '&'; } @@ -1043,7 +1043,7 @@ class Tokenizer else { // Convert from decimal to char. $numeric = $this->scanner->getNumeric(); - if ($numeric === FALSE) { + if ($numeric === false) { $this->parseError("Expected &#DIGITS;, got &#%s", $tok); $this->scanner->unconsume(2); return '&'; @@ -1056,7 +1056,7 @@ class Tokenizer // [a-zA-Z0-9]+; $cname = $this->scanner->getAsciiAlpha(); $entity = CharacterReference::lookupName($cname); - if ($entity == NULL) { + if ($entity == null) { $this->parseError("No match in entity table for '%s'", $entity); } } diff --git a/src/HTML5/Parser/TreeBuildingRules.php b/src/HTML5/Parser/TreeBuildingRules.php index 4eb0a54..2af3c66 100644 --- a/src/HTML5/Parser/TreeBuildingRules.php +++ b/src/HTML5/Parser/TreeBuildingRules.php @@ -44,7 +44,7 @@ class TreeBuildingRules } /** - * Returns TRUE if the given tagname has special processing rules. + * Returns true if the given tagname has special processing rules. */ public function hasRules($tagname) { diff --git a/src/HTML5/Parser/UTF8Utils.php b/src/HTML5/Parser/UTF8Utils.php index ed35997..d319252 100644 --- a/src/HTML5/Parser/UTF8Utils.php +++ b/src/HTML5/Parser/UTF8Utils.php @@ -86,7 +86,7 @@ class UTF8Utils // details. if (function_exists('mb_convert_encoding')) { // mb library has the following behaviors: - // - UTF-16 surrogates result in FALSE. + // - UTF-16 surrogates result in false. // - Overlongs and outside Plane 16 result in empty strings. // Before we run mb_convert_encoding we need to tell it what to do with @@ -138,7 +138,7 @@ class UTF8Utils $errors = array(); /* - * All U+0000 NULL characters in the input must be replaced by U+FFFD REPLACEMENT CHARACTERs. Any occurrences of such characters is a parse error. + * All U+0000 null characters in the input must be replaced by U+FFFD REPLACEMENT CHARACTERs. Any occurrences of such characters is a parse error. */ for ($i = 0, $count = substr_count($data, "\0"); $i < $count; $i ++) { $errors[] = 'null-character'; diff --git a/src/HTML5/Serializer/OutputRules.php b/src/HTML5/Serializer/OutputRules.php index 6f02956..2969383 100644 --- a/src/HTML5/Serializer/OutputRules.php +++ b/src/HTML5/Serializer/OutputRules.php @@ -24,7 +24,7 @@ class OutputRules implements \Masterminds\HTML5\Serializer\RulesInterface protected $traverser; - protected $encode = FALSE; + protected $encode = false; protected $out; @@ -179,7 +179,7 @@ class OutputRules implements \Masterminds\HTML5\Serializer\RulesInterface $len = $map->length; for ($i = 0; $i < $len; ++ $i) { $node = $map->item($i); - $val = $this->enc($node->value, TRUE); + $val = $this->enc($node->value, true); // XXX: The spec says that we need to ensure that anything in // the XML, XMLNS, or XLink NS's should use the canonical @@ -249,7 +249,7 @@ class OutputRules implements \Masterminds\HTML5\Serializer\RulesInterface /** * Encode text. * - * When encode is set to FALSE, the default value, the text passed in is + * When encode is set to false, the default value, the text passed in is * escaped per section 8.3 of the html5 spec. For details on how text is * escaped see the escape() method. * @@ -275,7 +275,7 @@ class OutputRules implements \Masterminds\HTML5\Serializer\RulesInterface * * @return string The encoded text. */ - protected function enc($text, $attribute = FALSE) + protected function enc($text, $attribute = false) { // Escape the text rather than convert to named character references. @@ -286,7 +286,7 @@ class OutputRules implements \Masterminds\HTML5\Serializer\RulesInterface // If we are in PHP 5.4+ we can use the native html5 entity functionality to // convert the named character references. if (defined('ENT_HTML5')) { - return htmlentities($text, ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES, 'UTF-8', FALSE); + return htmlentities($text, ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES, 'UTF-8', false); } // If a version earlier than 5.4 html5 entities are not entirely handled. // This manually handles them. else { @@ -313,7 +313,7 @@ class OutputRules implements \Masterminds\HTML5\Serializer\RulesInterface * @param boolean $attribute * True if we are escaping an attrubute, false otherwise */ - protected function escape($text, $attribute = FALSE) + protected function escape($text, $attribute = false) { // Not using htmlspecialchars because, while it does escaping, it doesn't diff --git a/src/HTML5/Serializer/Traverser.php b/src/HTML5/Serializer/Traverser.php index 3bd55b4..e910f3a 100644 --- a/src/HTML5/Serializer/Traverser.php +++ b/src/HTML5/Serializer/Traverser.php @@ -26,7 +26,7 @@ class Traverser protected $options; - protected $encode = FALSE; + protected $encode = false; protected $rules; @@ -43,7 +43,7 @@ class Traverser * @param array $options * An array or options for the traverser as key/value pairs. These include: * - encode_entities: A bool to specify if full encding should happen for all named - * charachter references. Defaults to FALSE which escapes &'<>". + * charachter references. Defaults to false which escapes &'<>". * - output_rules: The path to the class handling the output rules. */ public function __construct($dom, $out, RulesInterface $rules, $options = array()) @@ -142,7 +142,7 @@ class Traverser { $uri = $ele->namespaceURI; if (empty($uri)) { - return FALSE; + return false; } return isset(static::$local_ns[$uri]); diff --git a/test/HTML5/Html5Test.php b/test/HTML5/Html5Test.php index 851b2e4..2b46b23 100644 --- a/test/HTML5/Html5Test.php +++ b/test/HTML5/Html5Test.php @@ -129,18 +129,18 @@ class Html5Test extends TestCase { $html5 = $this->getInstance(); $options = $html5->getOptions(); - $this->assertEquals(FALSE, $options['encode_entities']); + $this->assertEquals(false, $options['encode_entities']); $html5 = $this->getInstance(array( 'foo' => 'bar', - 'encode_entities' => TRUE + 'encode_entities' => true )); $options = $html5->getOptions(); $this->assertEquals('bar', $options['foo']); - $this->assertEquals(TRUE, $options['encode_entities']); + $this->assertEquals(true, $options['encode_entities']); // Need to reset to original so future tests pass as expected. - // $this->getInstance()->setOption('encode_entities', FALSE); + // $this->getInstance()->setOption('encode_entities', false); } public function testSvg() diff --git a/test/HTML5/Parser/DOMTreeBuilderTest.php b/test/HTML5/Parser/DOMTreeBuilderTest.php index 266ca98..0046d88 100644 --- a/test/HTML5/Parser/DOMTreeBuilderTest.php +++ b/test/HTML5/Parser/DOMTreeBuilderTest.php @@ -21,7 +21,7 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase */ protected function parse($string, array $options = array()) { - $treeBuilder = new DOMTreeBuilder(FALSE, $options); + $treeBuilder = new DOMTreeBuilder(false, $options); $input = new StringInputStream($string); $scanner = new Scanner($input); $parser = new Tokenizer($scanner, $treeBuilder); @@ -36,7 +36,7 @@ class DOMTreeBuilderTest extends \Masterminds\HTML5\Tests\TestCase */ protected function parseFragment($string) { - $treeBuilder = new DOMTreeBuilder(TRUE); + $treeBuilder = new DOMTreeBuilder(true); $input = new StringInputStream($string); $scanner = new Scanner($input); $parser = new Tokenizer($scanner, $treeBuilder); diff --git a/test/HTML5/Parser/EventStack.php b/test/HTML5/Parser/EventStack.php index da0d3ec..60e2abe 100644 --- a/test/HTML5/Parser/EventStack.php +++ b/test/HTML5/Parser/EventStack.php @@ -42,7 +42,7 @@ class EventStack implements EventHandler return $this->stack[$index]; } - protected function store($event, $data = NULL) + protected function store($event, $data = null) { $this->stack[] = array( 'name' => $event, @@ -50,7 +50,7 @@ class EventStack implements EventHandler ); } - public function doctype($name, $type = 0, $id = NULL, $quirks = FALSE) + public function doctype($name, $type = 0, $id = null, $quirks = false) { $args = array( $name, @@ -61,7 +61,7 @@ class EventStack implements EventHandler $this->store('doctype', $args); } - public function startTag($name, $attributes = array(), $selfClosing = FALSE) + public function startTag($name, $attributes = array(), $selfClosing = false) { $args = func_get_args(); $this->store('startTag', $args); @@ -109,7 +109,7 @@ class EventStack implements EventHandler $this->store('error', func_get_args()); } - public function processingInstruction($name, $data = NULL) + public function processingInstruction($name, $data = null) { $this->store('pi', func_get_args()); } diff --git a/test/HTML5/Parser/InstructionProcessorMock.php b/test/HTML5/Parser/InstructionProcessorMock.php index ec69364..32a2204 100644 --- a/test/HTML5/Parser/InstructionProcessorMock.php +++ b/test/HTML5/Parser/InstructionProcessorMock.php @@ -4,9 +4,9 @@ namespace Masterminds\HTML5\Tests\Parser; class InstructionProcessorMock implements \Masterminds\HTML5\InstructionProcessor { - public $name = NULL; + public $name = null; - public $data = NULL; + public $data = null; public $count = 0; diff --git a/test/HTML5/Parser/StringInputStreamTest.php b/test/HTML5/Parser/StringInputStreamTest.php index 3ee768a..f87cc10 100644 --- a/test/HTML5/Parser/StringInputStreamTest.php +++ b/test/HTML5/Parser/StringInputStreamTest.php @@ -176,7 +176,7 @@ class StringInputStreamTest extends \Masterminds\HTML5\Tests\TestCase // Replace NULL with Unicode replacement. $stream = new StringInputStream("\0\0\0"); $this->assertEquals("\xEF\xBF\xBD\xEF\xBF\xBD\xEF\xBF\xBD", $stream->remainingChars(), 'Null character should be replaced by U+FFFD'); - $this->assertEquals(3, count($stream->errors), 'Null character should set parse error: ' . print_r($stream->errors, TRUE)); + $this->assertEquals(3, count($stream->errors), 'Null character should set parse error: ' . print_r($stream->errors, true)); // Remove CR when next to LF. $stream = new StringInputStream("\r\n"); diff --git a/test/HTML5/Parser/TokenizerTest.php b/test/HTML5/Parser/TokenizerTest.php index 32f0fcb..9f0f4b4 100644 --- a/test/HTML5/Parser/TokenizerTest.php +++ b/test/HTML5/Parser/TokenizerTest.php @@ -21,11 +21,11 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase */ public function assertEventEquals($type, $expects, $event) { - $this->assertEquals($type, $event['name'], "Event $type for " . print_r($event, TRUE)); + $this->assertEquals($type, $event['name'], "Event $type for " . print_r($event, true)); if (is_array($expects)) { - $this->assertEquals($expects, $event['data'], "Event $type should equal " . print_r($expects, TRUE) . ": " . print_r($event, TRUE)); + $this->assertEquals($expects, $event['data'], "Event $type should equal " . print_r($expects, true) . ": " . print_r($event, true)); } else { - $this->assertEquals($expects, $event['data'][0], "Event $type should equal $expects: " . print_r($event, TRUE)); + $this->assertEquals($expects, $event['data'][0], "Event $type should equal $expects: " . print_r($event, true)); } } @@ -34,7 +34,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase */ public function assertEventError($event) { - $this->assertEquals('error', $event['name'], "Expected error for event: " . print_r($event, TRUE)); + $this->assertEquals('error', $event['name'], "Expected error for event: " . print_r($event, true)); } /** @@ -47,15 +47,15 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase * - event name * - matches on event 0. */ - protected function isAllGood($name, $depth, $tests, $debug = FALSE) + protected function isAllGood($name, $depth, $tests, $debug = false) { foreach ($tests as $try => $expects) { if ($debug) { - fprintf(STDOUT, "%s expects %s\n", $try, print_r($expects, TRUE)); + fprintf(STDOUT, "%s expects %s\n", $try, print_r($expects, true)); } $e = $this->parse($try); if ($depth > 0) { - $this->assertEquals($depth, $e->depth(), "Expected depth $depth for test $try." . print_r($e, TRUE)); + $this->assertEquals($depth, $e->depth(), "Expected depth $depth for test $try." . print_r($e, true)); } $this->assertEventEquals($name, $expects, $e->get(0)); } @@ -238,171 +238,171 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase '<!DOCTYPE html>' => array( 'html', 0, - NULL, - FALSE + null, + false ), '<!doctype html>' => array( 'html', 0, - NULL, - FALSE + null, + false ), '<!DocType html>' => array( 'html', 0, - NULL, - FALSE + null, + false ), "<!DOCTYPE\nhtml>" => array( 'html', 0, - NULL, - FALSE + null, + false ), "<!DOCTYPE\fhtml>" => array( 'html', 0, - NULL, - FALSE + null, + false ), '<!DOCTYPE html PUBLIC "foo bar">' => array( 'html', EventStack::DOCTYPE_PUBLIC, 'foo bar', - FALSE + false ), "<!DOCTYPE html PUBLIC 'foo bar'>" => array( 'html', EventStack::DOCTYPE_PUBLIC, 'foo bar', - FALSE + false ), '<!DOCTYPE html PUBLIC "foo bar" >' => array( 'html', EventStack::DOCTYPE_PUBLIC, 'foo bar', - FALSE + false ), "<!DOCTYPE html \nPUBLIC\n'foo bar'>" => array( 'html', EventStack::DOCTYPE_PUBLIC, 'foo bar', - FALSE + false ), '<!DOCTYPE html SYSTEM "foo bar">' => array( 'html', EventStack::DOCTYPE_SYSTEM, 'foo bar', - FALSE + false ), "<!DOCTYPE html SYSTEM 'foo bar'>" => array( 'html', EventStack::DOCTYPE_SYSTEM, 'foo bar', - FALSE + false ), '<!DOCTYPE html SYSTEM "foo/bar" >' => array( 'html', EventStack::DOCTYPE_SYSTEM, 'foo/bar', - FALSE + false ), "<!DOCTYPE html \nSYSTEM\n'foo bar'>" => array( 'html', EventStack::DOCTYPE_SYSTEM, 'foo bar', - FALSE + false ) ); $this->isAllGood('doctype', 2, $good); $bad = array( '<!DOCTYPE>' => array( - NULL, + null, EventStack::DOCTYPE_NONE, - NULL, - TRUE + null, + true ), '<!DOCTYPE >' => array( - NULL, + null, EventStack::DOCTYPE_NONE, - NULL, - TRUE + null, + true ), '<!DOCTYPE foo' => array( 'foo', EventStack::DOCTYPE_NONE, - NULL, - TRUE + null, + true ), '<!DOCTYPE foo PUB' => array( 'foo', EventStack::DOCTYPE_NONE, - NULL, - TRUE + null, + true ), '<!DOCTYPE foo PUB>' => array( 'foo', EventStack::DOCTYPE_NONE, - NULL, - TRUE + null, + true ), '<!DOCTYPE foo PUB "Looks good">' => array( 'foo', EventStack::DOCTYPE_NONE, - NULL, - TRUE + null, + true ), '<!DOCTYPE foo SYSTME "Looks good"' => array( 'foo', EventStack::DOCTYPE_NONE, - NULL, - TRUE + null, + true ), // Can't tell whether these are ids or ID types, since the context is chopped. '<!DOCTYPE foo PUBLIC' => array( 'foo', EventStack::DOCTYPE_NONE, - NULL, - TRUE + null, + true ), '<!DOCTYPE foo PUBLIC>' => array( 'foo', EventStack::DOCTYPE_NONE, - NULL, - TRUE + null, + true ), '<!DOCTYPE foo SYSTEM' => array( 'foo', EventStack::DOCTYPE_NONE, - NULL, - TRUE + null, + true ), '<!DOCTYPE foo SYSTEM>' => array( 'foo', EventStack::DOCTYPE_NONE, - NULL, - TRUE + null, + true ), '<!DOCTYPE html SYSTEM "foo bar"' => array( 'html', EventStack::DOCTYPE_SYSTEM, 'foo bar', - TRUE + true ), '<!DOCTYPE html SYSTEM "foo bar" more stuff>' => array( 'html', EventStack::DOCTYPE_SYSTEM, 'foo bar', - TRUE + true ) ); foreach ($bad as $test => $expects) { $events = $this->parse($test); // fprintf(STDOUT, $test . PHP_EOL); - $this->assertEquals(3, $events->depth(), "Counting events for '$test': " . print_r($events, TRUE)); + $this->assertEquals(3, $events->depth(), "Counting events for '$test': " . print_r($events, true)); $this->assertEventError($events->get(0)); $this->assertEventEquals('doctype', $expects, $events->get(1)); } @@ -448,7 +448,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase ); foreach ($selfClose as $test => $expects) { $events = $this->parse($test); - $this->assertEquals(3, $events->depth(), "Counting events for '$test'" . print_r($events, TRUE)); + $this->assertEquals(3, $events->depth(), "Counting events for '$test'" . print_r($events, true)); $this->assertEventEquals('startTag', $expects, $events->get(0)); $this->assertEventEquals('endTag', $expects, $events->get(1)); } @@ -462,7 +462,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase foreach ($bad as $test => $expects) { $events = $this->parse($test); - $this->assertEquals(3, $events->depth(), "Counting events for '$test': " . print_r($events, TRUE)); + $this->assertEquals(3, $events->depth(), "Counting events for '$test': " . print_r($events, true)); $this->assertEventError($events->get(0)); $this->assertEventEquals('startTag', $expects, $events->get(1)); } @@ -484,7 +484,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase $this->assertEventError($events->get(1)); $this->assertEventError($events->get(2)); $this->assertEventEquals('startTag', $expected, $events->get(3)); - $this->assertEventEquals('eof', NULL, $events->get(4)); + $this->assertEventEquals('eof', null, $events->get(4)); } } @@ -510,7 +510,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase $this->assertEventError($events->get(0)); $this->assertEventEquals('startTag', $expected[0], $events->get(1)); $this->assertEventEquals('startTag', $expected[1], $events->get(2)); - $this->assertEventEquals('eof', NULL, $events->get(3)); + $this->assertEventEquals('eof', null, $events->get(3)); } $events = $this->parse('<span<>02</span>'); @@ -519,20 +519,20 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase $this->assertEventError($events->get(2)); $this->assertEventEquals('text', '>02', $events->get(3)); $this->assertEventEquals('endTag', 'span', $events->get(4)); - $this->assertEventEquals('eof', NULL, $events->get(5)); + $this->assertEventEquals('eof', null, $events->get(5)); $events = $this->parse('<p</p>'); $this->assertEventError($events->get(0)); $this->assertEventEquals('startTag', 'p', $events->get(1)); $this->assertEventEquals('endTag', 'p', $events->get(2)); - $this->assertEventEquals('eof', NULL, $events->get(3)); + $this->assertEventEquals('eof', null, $events->get(3)); $events = $this->parse('<strong><WordPress</strong>'); $this->assertEventEquals('startTag', 'strong', $events->get(0)); $this->assertEventError($events->get(1)); $this->assertEventEquals('startTag', 'wordpress', $events->get(2)); $this->assertEventEquals('endTag', 'strong', $events->get(3)); - $this->assertEventEquals('eof', NULL, $events->get(4)); + $this->assertEventEquals('eof', null, $events->get(4)); $events = $this->parse('<src=<a>'); $this->assertEventError($events->get(0)); @@ -540,12 +540,12 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase $this->assertEventError($events->get(2)); $this->assertEventEquals('startTag', 'src', $events->get(3)); $this->assertEventEquals('startTag', 'a', $events->get(4)); - $this->assertEventEquals('eof', NULL, $events->get(5)); + $this->assertEventEquals('eof', null, $events->get(5)); $events = $this->parse('<br...<a>'); $this->assertEventError($events->get(0)); $this->assertEventEquals('startTag', 'br', $events->get(1)); - $this->assertEventEquals('eof', NULL, $events->get(2)); + $this->assertEventEquals('eof', null, $events->get(2)); } public function testIllegalTagNames() @@ -579,35 +579,35 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase array( 'bar' => 'baz' ), - FALSE + false ), '<foo bar=" baz ">' => array( 'foo', array( 'bar' => ' baz ' ), - FALSE + false ), "<foo bar=\"\nbaz\n\">" => array( 'foo', array( 'bar' => "\nbaz\n" ), - FALSE + false ), "<foo bar='baz'>" => array( 'foo', array( 'bar' => 'baz' ), - FALSE + false ), '<foo bar="A full sentence.">' => array( 'foo', array( 'bar' => 'A full sentence.' ), - FALSE + false ), "<foo a='1' b=\"2\">" => array( 'foo', @@ -615,50 +615,50 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase 'a' => '1', 'b' => '2' ), - FALSE + false ), "<foo ns:bar='baz'>" => array( 'foo', array( 'ns:bar' => 'baz' ), - FALSE + false ), "<foo a='blue&red'>" => array( 'foo', array( 'a' => 'blue&red' ), - FALSE + false ), "<foo a='blue&&red'>" => array( 'foo', array( 'a' => 'blue&&red' ), - FALSE + false ), "<foo\nbar='baz'\n>" => array( 'foo', array( 'bar' => 'baz' ), - FALSE + false ), '<doe a deer>' => array( 'doe', array( - 'a' => NULL, - 'deer' => NULL + 'a' => null, + 'deer' => null ), - FALSE + false ), '<foo bar=baz>' => array( 'foo', array( 'bar' => 'baz' ), - FALSE + false ), // Updated for 8.1.2.3 @@ -667,7 +667,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase array( 'bar' => 'baz' ), - FALSE + false ), // The spec allows an unquoted value '/'. This will not be a closing @@ -677,14 +677,14 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase array( 'bar' => '/' ), - FALSE + false ), '<foo bar=baz/>' => array( 'foo', array( 'bar' => 'baz/' ), - FALSE + false ) ); $this->isAllGood('startTag', 2, $good); @@ -696,21 +696,21 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase array( 'bar' => 'baz' ), - TRUE + true ), '<foo BAR="baz"/>' => array( 'foo', array( 'bar' => 'baz' ), - TRUE + true ), '<foo BAR="BAZ"/>' => array( 'foo', array( 'bar' => 'BAZ' ), - TRUE + true ), "<foo a='1' b=\"2\" c=3 d/>" => array( 'foo', @@ -718,9 +718,9 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase 'a' => '1', 'b' => '2', 'c' => '3', - 'd' => NULL + 'd' => null ), - TRUE + true ) ); $this->isAllGood('startTag', 3, $withEnd); @@ -733,35 +733,35 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase array( 'a' => 'blue&red' ), - FALSE + false ), "<foo a='blue&&&red'>" => array( 'foo', array( 'a' => 'blue&&&red' ), - FALSE + false ), '<foo bar=>' => array( 'foo', array( - 'bar' => NULL + 'bar' => null ), - FALSE + false ), '<foo bar="oh' => array( 'foo', array( 'bar' => 'oh' ), - FALSE + false ), '<foo bar=oh">' => array( 'foo', array( 'bar' => 'oh"' ), - FALSE + false ), // these attributes are ignored because of current implementation @@ -770,28 +770,28 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase '<foo b"="baz">' => array( 'foo', array(), - FALSE + false ), '<foo 2abc="baz">' => array( 'foo', array(), - FALSE + false ), '<foo ?="baz">' => array( 'foo', array(), - FALSE + false ), '<foo foo?bar="baz">' => array( 'foo', array(), - FALSE + false ) ) ; foreach ($bad as $test => $expects) { $events = $this->parse($test); - $this->assertEquals(3, $events->depth(), "Counting events for '$test': " . print_r($events, TRUE)); + $this->assertEquals(3, $events->depth(), "Counting events for '$test': " . print_r($events, true)); $this->assertEventError($events->get(0)); $this->assertEventEquals('startTag', $expects, $events->get(1)); } @@ -801,15 +801,15 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase '<foo ="bar">' => array( 'foo', array( - '=' => NULL, - '"bar"' => NULL + '=' => null, + '"bar"' => null ), - FALSE + false ), '<foo////>' => array( 'foo', array(), - TRUE + true ), // character "&" in unquoted attribute shouldn't cause an infinite loop '<foo bar=index.php?str=1&id=29>' => array( @@ -817,19 +817,19 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase array( 'bar' => 'index.php?str=1&id=29' ), - FALSE + false ) ); foreach ($reallyBad as $test => $expects) { $events = $this->parse($test); - // fprintf(STDOUT, $test . print_r($events, TRUE)); + // fprintf(STDOUT, $test . print_r($events, true)); $this->assertEventError($events->get(0)); $this->assertEventError($events->get(1)); // $this->assertEventEquals('startTag', $expects, $events->get(1)); } // Regression: Malformed elements should be detected. - // '<foo baz="1" <bar></foo>' => array('foo', array('baz' => '1'), FALSE), + // '<foo baz="1" <bar></foo>' => array('foo', array('baz' => '1'), false), $events = $this->parse('<foo baz="1" <bar></foo>'); $this->assertEventError($events->get(0)); $this->assertEventEquals('startTag', array( @@ -837,12 +837,12 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase array( 'baz' => '1' ), - FALSE + false ), $events->get(1)); $this->assertEventEquals('startTag', array( 'bar', array(), - FALSE + false ), $events->get(2)); $this->assertEventEquals('endTag', array( 'foo' @@ -874,7 +874,7 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase ); foreach ($bad as $test => $expects) { $events = $this->parse($test); - $this->assertEquals(4, $events->depth(), "Counting events for '$test': " . print_r($events, TRUE)); + $this->assertEquals(4, $events->depth(), "Counting events for '$test': " . print_r($events, true)); $this->assertEventEquals('startTag', 'script', $events->get(0)); $this->assertEventError($events->get(1)); $this->assertEventEquals('text', $expects, $events->get(2)); @@ -898,38 +898,38 @@ class TokenizerTest extends \Masterminds\HTML5\Tests\TestCase public function testText() { $events = $this->parse('a<br>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('startTag', 'br', $events->get(1)); $this->assertEventEquals('text', 'b', $events->get(2)); $events = $this->parse('<a>Test</a>'); - $this->assertEquals(4, $events->depth(), "Events: " . print_r($events, TRUE)); + $this->assertEquals(4, $events->depth(), "Events: " . print_r($events, true)); $this->assertEventEquals('startTag', 'a', $events->get(0)); $this->assertEventEquals('text', 'Test', $events->get(1)); $this->assertEventEquals('endTag', 'a', $events->get(2)); $events = $this->parse('a<![CDATA[test]]>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('cdata', 'test', $events->get(1)); $this->assertEventEquals('text', 'b', $events->get(2)); $events = $this->parse('a<!--test-->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)); |