Browse Source

Remove uses of is_null for consistency

ns
J. King 3 years ago
parent
commit
aaf85387be
  1. 2
      README.md
  2. 4
      lib/Charset.php
  3. 2
      lib/DOM/Element.php
  4. 6
      lib/DOM/traits/Serialize.php
  5. 4
      lib/OpenElementsStack.php
  6. 2
      lib/ParseError.php
  7. 2
      lib/Stack.php
  8. 2
      lib/Token.php
  9. 6
      lib/Tokenizer.php
  10. 11
      lib/TreeBuilder.php

2
README.md

@ -37,7 +37,7 @@ This library and [masterminds/html5](https://packagist.org/packages/masterminds/
| Handling of processing instructions | Processing instructions are retained | Per specification |
| Handling of bogus XLink namespace\* | XLink attributes are lost if preceded by bogus namespace | Bogus namespace is ignored |
| Namespace for HTML elements | Per specification, configurable | Null |
| Time needed to parse single-page HTML specification | 2.7 seconds† | 6.2 seconds‡ |
| Time needed to parse single-page HTML specification | 2.7 seconds† | 6.0 seconds‡ |
| Peak memory needed for same | 38 MB | 13.9 MB |
\* For example: `<svg xmlns:xlink='http://www.w3.org/1999/xhtml' xlink:href='http://example.com/'/>`. It is unclear what correct behaviour is, but we believe our behaviour to be more consistent with the intent of the specification.

4
lib/Charset.php

@ -135,7 +135,7 @@ abstract class Charset {
# null, let charset be the encoding returned, and set need pragma to true.
// OPTIMIZATION: Check if charset is null before performing the algorithm
if (is_null($charset) && $candidate = self::fromMeta($attr['value'])) {
if ($charset === null && $candidate = self::fromMeta($attr['value'])) {
$charset = $candidate;
$needPragma = true;
}
@ -152,7 +152,7 @@ abstract class Charset {
# Processing: If need pragma is null, then jump to the step below labeled next byte.
# If need pragma is true but got pragma is false, then jump to the step below labeled next byte.
if (is_null($needPragma) || ($needPragma && !$gotPragma)) {
if ($needPragma === null || ($needPragma && !$gotPragma)) {
continue;
}
# If charset is failure, then jump to the step below labeled next byte.

2
lib/DOM/Element.php

@ -190,7 +190,7 @@ class Element extends \DOMElement {
# If current node is an element in the HTML namespace, the MathML namespace,
# or the SVG namespace, then let tagname be current node’s local name.
# Otherwise, let tagname be current node’s qualified name.
if (is_null($this->namespaceURI) || $this->namespaceURI === Parser::MATHML_NAMESPACE || $this->namespaceURI === Parser::SVG_NAMESPACE) {
if ($this->namespaceURI === null || $this->namespaceURI === Parser::MATHML_NAMESPACE || $this->namespaceURI === Parser::SVG_NAMESPACE) {
$tagName = $this->localName;
} else {
$tagName = $this->nodeName;

6
lib/DOM/traits/Serialize.php

@ -15,9 +15,7 @@ trait Serialize {
}
protected function serialize(\DOMNode $node = null): string {
if (is_null($node)) {
$node = $this;
}
$node = $node ?? $this;
if (!$node instanceof Element && !$node instanceof Document && !$node instanceof DocumentFragment) {
throw new DOMException(DOMException::DOCUMENT_ELEMENT_DOCUMENTFRAG_EXPECTED, gettype($node));
@ -70,4 +68,4 @@ trait Serialize {
# 5. Return s.
return $s;
}
}
}

4
lib/OpenElementsStack.php

@ -105,7 +105,7 @@ class OpenElementsStack extends Stack {
// or element then we have a problem. Additionally, if the parser is created for
// parsing a fragment and the fragment context is null then we have a problem,
// too.
assert(is_null($fragmentContext) || $fragmentContext instanceof \DOMDocumentFragment || $fragmentContext instanceof \DOMDocument || $fragmentContext instanceof \DOMElement,new Exception(Exception::STACK_ELEMENT_DOCUMENT_DOCUMENTFRAG_EXPECTED));
assert($fragmentContext === null || $fragmentContext instanceof \DOMDocumentFragment || $fragmentContext instanceof \DOMDocument || $fragmentContext instanceof \DOMElement,new Exception(Exception::STACK_ELEMENT_DOCUMENT_DOCUMENTFRAG_EXPECTED));
$this->fragmentContext = $fragmentContext;
}
@ -118,7 +118,7 @@ class OpenElementsStack extends Stack {
public function offsetSet($offset, $value) {
assert($offset >= 0, new Exception(Exception::STACK_INVALID_INDEX, $offset));
if (is_null($offset)) {
if ($offset === null) {
$this->_storage[] = $value;
} else {
$this->_storage[$offset] = $value;

2
lib/ParseError.php

@ -181,7 +181,7 @@ class ParseError {
return 'Newline';
} elseif ($value === "\t") {
return 'Tab';
} elseif (is_null($value)) {
} elseif ($value === null) {
return 'nothing';
} else {
return $value;

2
lib/Stack.php

@ -9,7 +9,7 @@ abstract class Stack implements \ArrayAccess, \Countable, \IteratorAggregate {
public function offsetSet($offset, $value) {
assert($offset >= 0, new Exception(Exception::STACK_INVALID_INDEX, $offset));
if (is_null($offset)) {
if ($offset === null) {
$this->_storage[] = $value;
} else {
$this->_storage[$offset] = $value; // @codeCoverageIgnore

2
lib/Token.php

@ -71,7 +71,7 @@ abstract class TagToken extends Token {
}
public function hasAttribute(string $name): bool {
return (!is_null($this->_getAttributeKey($name)));
return ($this->_getAttributeKey($name) !== null);
}
public function getAttribute(string $name) {

6
lib/Tokenizer.php

@ -3412,10 +3412,10 @@ class Tokenizer {
}
// Look for an exact match; if not found look for a prefix match
$match = CharacterReference::NAMES[$candidate] ?? null;
if (is_null($match)) {
if ($match === null) {
$match = (preg_match(CharacterReference::PREFIX_PATTERN, $candidate, $match)) ? $match[0] : null;
// If a prefix match is found, unconsume to the end of the prefix and look up the entry in the table
if (!is_null($match)) {
if ($match !== null) {
$this->data->unconsume(strlen($candidate) - strlen($match));
$next = $candidate[strlen($match)];
$candidate = $match;
@ -3427,7 +3427,7 @@ class Tokenizer {
$this->temporaryBuffer .= $candidate;
# If there is a match
if (!is_null($match)) {
if ($match !== null) {
# If the character reference was consumed as part of an attribute,
# and the last character matched is not a U+003B SEMICOLON character (;),
# and the next input character is either a U+003D EQUALS SIGN character (=)

11
lib/TreeBuilder.php

@ -1381,8 +1381,8 @@ class TreeBuilder {
|| strpos($public, '-//w3o//dtd w3 html 3.0//') === 0
|| strpos($public, '-//webtechs//dtd mozilla html 2.0//') === 0
|| strpos($public, '-//webtechs//dtd mozilla html//') === 0
|| (is_null($token->system) && strpos($public, '-//w3c//dtd html 4.01 frameset//') === 0)
|| (is_null($token->system) && strpos($public, '-//w3c//dtd html 4.01 transitional//') === 0)
|| ($token->system === null && strpos($public, '-//w3c//dtd html 4.01 frameset//') === 0)
|| ($token->system === null && strpos($public, '-//w3c//dtd html 4.01 transitional//') === 0)
) {
$this->DOM->quirksMode = Document::QUIRKS_MODE;
}
@ -1394,8 +1394,8 @@ class TreeBuilder {
elseif (
strpos($public, '-//w3c//dtd xhtml 1.0 frameset//') === 0
|| strpos($public, '-//w3c//dtd xhtml 1.0 transitional//') === 0
|| (!is_null($token->system) && strpos($public, '-//w3c//dtd html 4.01 frameset//') === 0)
|| (!is_null($token->system) && strpos($public, '-//w3c//dtd html 4.01 transitional//') === 0)
|| ($token->system !== null && strpos($public, '-//w3c//dtd html 4.01 frameset//') === 0)
|| ($token->system !== null && strpos($public, '-//w3c//dtd html 4.01 transitional//') === 0)
) {
$this->DOM->quirksMode = Document::LIMITED_QUIRKS_MODE;
}
@ -3474,7 +3474,6 @@ class TreeBuilder {
}
# Any other start tag
else {
// ¡TEMPORARY!
foreignContentAnyOtherStartTag:
$currentNodeNamespace = $this->stack->currentNodeNamespace;
# If the adjusted current node is an element in the SVG namespace, and the
@ -4077,7 +4076,7 @@ class TreeBuilder {
elseif ($nodeName === 'html') {
# 1. If the head element pointer is null, switch the insertion mode to "before
# head" and abort these steps. (fragment case)
if (is_null($this->headElement)) {
if ($this->headElement === null) {
return $this->insertionMode = self::BEFORE_HEAD_MODE;
}
# 2. Otherwise, the head element pointer is not null, switch the insertion mode

Loading…
Cancel
Save