From 78c26bf451fc63d296a0d2f475043185a5696cf9 Mon Sep 17 00:00:00 2001 From: Tony Bogdanov Date: Sun, 1 Apr 2018 22:46:32 +0300 Subject: [PATCH] Fixed: selector matcher definitions --- classes/Dom.php | 4 +- classes/Node/Element.php | 1 + classes/SelectorMatcher.php | 31 +- .../SelectorMatcher/AttributeNodeTrait.php | 2 +- classes/SelectorMatcher/ClassNodeTrait.php | 2 +- .../CombinedSelectorNodeTrait.php | 2 +- classes/SelectorMatcher/ElementNodeTrait.php | 2 +- classes/SelectorMatcher/HashNodeTrait.php | 2 +- docs/coverage/Dom.php.html | 1404 +++++++++-------- docs/coverage/Node/CData.php.html | 2 +- docs/coverage/Node/Comment.php.html | 2 +- docs/coverage/Node/DocType.php.html | 2 +- docs/coverage/Node/Element.php.html | 231 +-- docs/coverage/Node/NodeInterface.php.html | 2 +- docs/coverage/Node/Text.php.html | 2 +- docs/coverage/Node/dashboard.html | 4 +- docs/coverage/Node/index.html | 6 +- docs/coverage/SelectorMatcher.php.html | 83 +- .../AttributeNodeTrait.php.html | 8 +- .../SelectorMatcher/ClassNodeTrait.php.html | 8 +- .../CombinedSelectorNodeTrait.php.html | 6 +- .../SelectorMatcher/ElementNodeTrait.php.html | 6 +- .../SelectorMatcher/HashNodeTrait.php.html | 6 +- docs/coverage/SelectorMatcher/dashboard.html | 2 +- docs/coverage/SelectorMatcher/index.html | 2 +- docs/coverage/dashboard.html | 44 +- docs/coverage/index.html | 22 +- docs/docs/class-SDom.Dom.html | 50 +- docs/docs/class-SDom.Node.Element.html | 14 +- docs/docs/class-SDom.SelectorMatcher.html | 2 +- docs/docs/source-class-SDom.Dom.html | 1334 ++++++++-------- docs/docs/source-class-SDom.Node.Element.html | 213 +-- .../source-class-SDom.SelectorMatcher.html | 65 +- ...om.SelectorMatcher.AttributeNodeTrait.html | 6 +- ...t-SDom.SelectorMatcher.ClassNodeTrait.html | 6 +- ...ctorMatcher.CombinedSelectorNodeTrait.html | 4 +- ...SDom.SelectorMatcher.ElementNodeTrait.html | 4 +- ...it-SDom.SelectorMatcher.HashNodeTrait.html | 4 +- ...om.SelectorMatcher.AttributeNodeTrait.html | 2 +- ...t-SDom.SelectorMatcher.ClassNodeTrait.html | 2 +- ...ctorMatcher.CombinedSelectorNodeTrait.html | 2 +- ...SDom.SelectorMatcher.ElementNodeTrait.html | 2 +- ...it-SDom.SelectorMatcher.HashNodeTrait.html | 2 +- 43 files changed, 1811 insertions(+), 1789 deletions(-) diff --git a/classes/Dom.php b/classes/Dom.php index 86fc9c6..a8f2f1e 100644 --- a/classes/Dom.php +++ b/classes/Dom.php @@ -228,7 +228,9 @@ public function __construct($content = null) * @var Tokens\Token $child */ foreach ($content->getChildren() as $child) { - $node->insertAfter((new static($child))->get(0)); + /** @var NodeInterface $childNode */ + $childNode = (new static($child))->get(0); + $node->insertAfter($childNode); } $this->nodes = [$node]; diff --git a/classes/Node/Element.php b/classes/Node/Element.php index fcd8834..848d99a 100644 --- a/classes/Node/Element.php +++ b/classes/Node/Element.php @@ -304,6 +304,7 @@ public function insertBefore(NodeInterface $node, NodeInterface $before = null): if (false === $index) { throw new \InvalidArgumentException('Only immediate child nodes can be used as insertBefore anchor.'); } + $index = (int) $index; } array_splice($this->children, $index, 0, [$node->attach($this)]); diff --git a/classes/SelectorMatcher.php b/classes/SelectorMatcher.php index 114bb27..dcd8240 100644 --- a/classes/SelectorMatcher.php +++ b/classes/SelectorMatcher.php @@ -2,13 +2,13 @@ namespace SDom; -use SDom\Node as Dom; +use SDom\Node as DomNode; use SDom\SelectorMatcher\AttributeNodeTrait; use SDom\SelectorMatcher\ClassNodeTrait; use SDom\SelectorMatcher\CombinedSelectorNodeTrait; use SDom\SelectorMatcher\ElementNodeTrait; use SDom\SelectorMatcher\HashNodeTrait; -use Symfony\Component\CssSelector\Node as Css; +use Symfony\Component\CssSelector\Node as CssNode; /** * A class for matching nodes against selector tokens. @@ -38,7 +38,7 @@ class SelectorMatcher */ public static function containsWord(string $word, string $sentence): bool { - return in_array($word, preg_split('/\s+/', $sentence)); + return in_array($word, preg_split('/\s+/', $sentence) ?: []); } /** @@ -47,30 +47,33 @@ public static function containsWord(string $word, string $sentence): bool * The $effectiveRoot specifies an Element node part of the hierarchy that is to be considered as root of the tree. * Immediate child nodes will be treated as if they don't have a parent. * - * @param Css\NodeInterface $token - * @param Dom\Element $node - * @param Dom\Element|null $effectiveRoot + * @param CssNode\NodeInterface $token + * @param DomNode\Element $node + * @param DomNode\Element|null $effectiveRoot * @return bool */ - public function match(Css\NodeInterface $token, Dom\Element $node, Dom\Element $effectiveRoot = null): bool - { + public function match( + CssNode\NodeInterface $token, + DomNode\Element $node, + DomNode\Element $effectiveRoot = null + ): bool { switch (true) { - case $token instanceof Css\SelectorNode: + case $token instanceof CssNode\SelectorNode: return $this->match($token->getTree(), $node, $effectiveRoot); - case $token instanceof Css\ElementNode: + case $token instanceof CssNode\ElementNode: return $this->matchElementNode($token, $node); - case $token instanceof Css\AttributeNode: + case $token instanceof CssNode\AttributeNode: return $this->matchAttributeNode($token, $node, $effectiveRoot); - case $token instanceof Css\ClassNode: + case $token instanceof CssNode\ClassNode: return $this->matchClassNode($token, $node, $effectiveRoot); - case $token instanceof Css\HashNode: + case $token instanceof CssNode\HashNode: return $this->matchHashNode($token, $node, $effectiveRoot); - case $token instanceof Css\CombinedSelectorNode: + case $token instanceof CssNode\CombinedSelectorNode: return $this->matchCombinedSelectorNode($token, $node, $effectiveRoot); default: diff --git a/classes/SelectorMatcher/AttributeNodeTrait.php b/classes/SelectorMatcher/AttributeNodeTrait.php index b73ed9a..a7a8266 100644 --- a/classes/SelectorMatcher/AttributeNodeTrait.php +++ b/classes/SelectorMatcher/AttributeNodeTrait.php @@ -3,9 +3,9 @@ namespace SDom\SelectorMatcher; use SDom\Node\Element; -use SDom\Node\NodeInterface; use SDom\SelectorMatcher; use Symfony\Component\CssSelector\Node\AttributeNode; +use Symfony\Component\CssSelector\Node\NodeInterface; /** * @pattern E[foo] diff --git a/classes/SelectorMatcher/ClassNodeTrait.php b/classes/SelectorMatcher/ClassNodeTrait.php index cfe7e6b..a2ffe72 100644 --- a/classes/SelectorMatcher/ClassNodeTrait.php +++ b/classes/SelectorMatcher/ClassNodeTrait.php @@ -3,9 +3,9 @@ namespace SDom\SelectorMatcher; use SDom\Node\Element; -use SDom\Node\NodeInterface; use SDom\SelectorMatcher; use Symfony\Component\CssSelector\Node\ClassNode; +use Symfony\Component\CssSelector\Node\NodeInterface; /** * @pattern E.warning diff --git a/classes/SelectorMatcher/CombinedSelectorNodeTrait.php b/classes/SelectorMatcher/CombinedSelectorNodeTrait.php index cb02edb..20fe49d 100644 --- a/classes/SelectorMatcher/CombinedSelectorNodeTrait.php +++ b/classes/SelectorMatcher/CombinedSelectorNodeTrait.php @@ -3,8 +3,8 @@ namespace SDom\SelectorMatcher; use SDom\Node\Element; -use SDom\Node\NodeInterface; use Symfony\Component\CssSelector\Node\CombinedSelectorNode; +use Symfony\Component\CssSelector\Node\NodeInterface; /** * @pattern E F diff --git a/classes/SelectorMatcher/ElementNodeTrait.php b/classes/SelectorMatcher/ElementNodeTrait.php index d0c500d..cc3fa67 100644 --- a/classes/SelectorMatcher/ElementNodeTrait.php +++ b/classes/SelectorMatcher/ElementNodeTrait.php @@ -3,8 +3,8 @@ namespace SDom\SelectorMatcher; use SDom\Node\Element; -use SDom\Node\NodeInterface; use Symfony\Component\CssSelector\Node\ElementNode; +use Symfony\Component\CssSelector\Node\NodeInterface; /** * @pattern * diff --git a/classes/SelectorMatcher/HashNodeTrait.php b/classes/SelectorMatcher/HashNodeTrait.php index 0a60233..3250fe8 100644 --- a/classes/SelectorMatcher/HashNodeTrait.php +++ b/classes/SelectorMatcher/HashNodeTrait.php @@ -3,8 +3,8 @@ namespace SDom\SelectorMatcher; use SDom\Node\Element; -use SDom\Node\NodeInterface; use Symfony\Component\CssSelector\Node\HashNode; +use Symfony\Component\CssSelector\Node\NodeInterface; /** * @pattern E#myid diff --git a/docs/coverage/Dom.php.html b/docs/coverage/Dom.php.html index 85ae0aa..caafadf 100644 --- a/docs/coverage/Dom.php.html +++ b/docs/coverage/Dom.php.html @@ -60,13 +60,13 @@
20 / 29
CRAP
-
- 73.39% covered (warning) +
+ 73.49% covered (warning)
-
73.39%
-
182 / 248
+
73.49%
+
183 / 249
@@ -87,15 +87,15 @@
68.97%
20 / 29
- 503.17 + 498.80
-
- 73.39% covered (warning) +
+ 73.49% covered (warning)
-
73.39%
-
182 / 248
+
73.49%
+
183 / 249
@@ -205,11 +205,11 @@
100.00%
-
46 / 46
+
47 / 47
-  __toString +  __toString
0.00% covered (danger) @@ -230,7 +230,7 @@ -  getIterator +  getIterator
n/a
0 / 0
@@ -241,7 +241,7 @@ -  anonymousFunction:292#1280 +  anonymousFunction:294#1289
100.00% covered (success) @@ -262,7 +262,7 @@ -  count +  count
100.00% covered (success) @@ -283,7 +283,7 @@ -  get +  get
100.00% covered (success) @@ -304,7 +304,7 @@ -  add +  add
100.00% covered (success) @@ -325,7 +325,7 @@ -  clear +  clear
100.00% covered (success) @@ -346,7 +346,7 @@ -  eq +  eq
100.00% covered (success) @@ -367,7 +367,7 @@ -  first +  first
100.00% covered (success) @@ -388,7 +388,7 @@ -  last +  last
100.00% covered (success) @@ -409,7 +409,7 @@ -  children +  children
100.00% covered (success) @@ -430,7 +430,7 @@ -  append +  append
0.00% covered (danger) @@ -451,7 +451,7 @@ -  prepend +  prepend
0.00% covered (danger) @@ -472,7 +472,7 @@ -  before +  before
0.00% covered (danger) @@ -493,7 +493,7 @@ -  after +  after
0.00% covered (danger) @@ -514,7 +514,7 @@ -  wrap +  wrap
100.00% covered (success) @@ -535,7 +535,7 @@ -  wrapInner +  wrapInner
100.00% covered (success) @@ -556,7 +556,7 @@ -  find +  find
100.00% covered (success) @@ -577,7 +577,7 @@ -  addClass +  addClass
100.00% covered (success) @@ -598,7 +598,7 @@ -  removeClass +  removeClass
100.00% covered (success) @@ -619,7 +619,7 @@ -  hasClass +  hasClass
100.00% covered (success) @@ -640,7 +640,7 @@ -  attr +  attr
0.00% covered (danger) @@ -661,7 +661,7 @@ -  removeAttr +  removeAttr
0.00% covered (danger) @@ -682,7 +682,7 @@ -  text +  text
0.00% covered (danger) @@ -703,7 +703,7 @@ -  html +  html
0.00% covered (danger) @@ -958,684 +958,686 @@                  * @var Tokens\Token $child                  */                 foreach ($content->getChildren() as $child) { -                     $node->insertAfter((new static($child))->get(0)); -                 } - -                 $this->nodes = [$node]; -                 break; - -             case $content instanceof Tokens\TokenCollection: -                 $this->nodes = []; - -                 /** @var Tokens\Token $token */ -                 foreach ($content as $token) { -                     $this->add($token); -                 } -                 break; - -             case is_string($content): -                 $this->nodes = []; - -                 try { -                     if (!isset(self::$tokenizer)) { -                         self::$tokenizer = new HtmlTokenizer(); -                     } -                     $tokenCollection = self::$tokenizer->parse($content); -                 } catch (\Exception $e) { -                     throw static::createInvalidContentException($content); -                 } - -                 /** @var Tokens\Token $token */ -                 foreach ($tokenCollection as $token) { -                     $this->add($token); -                 } -                 break; - -             default: -                 throw static::createInvalidContentException($content); -         } -     } - -     /** -      * Return the concatenated string representation of all nodes in the collection. -      * -      * @return string -      */ -     public function __toString(): string -     { -         $html = ''; - -         foreach ($this->nodes as $node) { -             $html .= (string) $node; -         } - -         return $html; -     } - -     /** -      * Return an \ArrayIterator with all nodes wrapped in a Dom instance. -      * -      * @return \ArrayIterator -      */ -     public function getIterator(): \ArrayIterator -     { -         return new \ArrayIterator(array_map(function (NodeInterface $node) { -             return new static($node); -         }, $this->nodes)); -     } - -     /** -      * Return the number of wrapped nodes. -      * -      * @return int -      */ -     public function count(): int -     { -         return count($this->nodes); -     } - -     /** -      * Retrieve a NodeInterface instance for the specified index, or an array of all NodeInterface instances if index -      * is not specified. -      * -      * Throw \OutOfBoundsException exception if the specified index is out of bounds. +                     /** @var NodeInterface $childNode */ +                     $childNode = (new static($child))->get(0); +                     $node->insertAfter($childNode); +                 } + +                 $this->nodes = [$node]; +                 break; + +             case $content instanceof Tokens\TokenCollection: +                 $this->nodes = []; + +                 /** @var Tokens\Token $token */ +                 foreach ($content as $token) { +                     $this->add($token); +                 } +                 break; + +             case is_string($content): +                 $this->nodes = []; + +                 try { +                     if (!isset(self::$tokenizer)) { +                         self::$tokenizer = new HtmlTokenizer(); +                     } +                     $tokenCollection = self::$tokenizer->parse($content); +                 } catch (\Exception $e) { +                     throw static::createInvalidContentException($content); +                 } + +                 /** @var Tokens\Token $token */ +                 foreach ($tokenCollection as $token) { +                     $this->add($token); +                 } +                 break; + +             default: +                 throw static::createInvalidContentException($content); +         } +     } + +     /** +      * Return the concatenated string representation of all nodes in the collection. +      * +      * @return string +      */ +     public function __toString(): string +     { +         $html = ''; + +         foreach ($this->nodes as $node) { +             $html .= (string) $node; +         } + +         return $html; +     } + +     /** +      * Return an \ArrayIterator with all nodes wrapped in a Dom instance. +      * +      * @return \ArrayIterator +      */ +     public function getIterator(): \ArrayIterator +     { +         return new \ArrayIterator(array_map(function (NodeInterface $node) { +             return new static($node); +         }, $this->nodes)); +     } + +     /** +      * Return the number of wrapped nodes. +      * +      * @return int +      */ +     public function count(): int +     { +         return count($this->nodes); +     } + +     /** +      * Retrieve a NodeInterface instance for the specified index, or an array of all NodeInterface instances if index +      * is not specified.      * -      * @param int|null $index -      * @return NodeInterface|NodeInterface[] -      */ -     public function get(int $index = null) -     { -         if (!isset($index)) { -             return $this->nodes; -         } - -         $count = count($this); +      * Throw \OutOfBoundsException exception if the specified index is out of bounds. +      * +      * @param int|null $index +      * @return NodeInterface|NodeInterface[] +      */ +     public function get(int $index = null) +     { +         if (!isset($index)) { +             return $this->nodes; +         } -         if ($index < 0 || $index >= $count) { -             throw new \OutOfBoundsException(sprintf( -                 'The requested node index %d is out of the collection bounds [%s].', -                 $index, -                 0 < $count ? '[0; ' . ($count - 1) . ']' : '(empty collection)' -             )); -         } - -         return $this->nodes[$index]; -     } - -     /** -      * Add the specified content to the end of the collection. -      * -      * @param $content -      * @return Dom -      */ -     public function add($content): Dom -     { -         /** @var NodeInterface $node */ -         foreach ((new static($content))->nodes as $node) { -             if (!in_array($node, $this->nodes, true)) { -                 $this->nodes[] = $node; -             } -         } - -         return $this; -     } - -     /** -      * Clear the collection. -      * -      * @return Dom -      */ -     public function clear(): Dom -     { -         $this->nodes = []; -         return $this; -     } - -     /** -      * Retrieve a new Dom collection where the set of matched elements is reduced to the one at the specified index. -      * If the specified index is out of bounds an empty collection is returned. -      * -      * @param int $index -      * @return Dom -      */ -     public function eq(int $index): Dom -     { -         return array_key_exists($index, $this->nodes) ? -             new static($this->nodes[$index]) : -             new static(); -     } - -     /** -      * Retrieve a new Dom collection where the set of matched elements is reduced to the first in the set. -      * If the collection is empty a new empty collection is returned. -      * -      * @return Dom -      */ -     public function first(): Dom -     { -         return $this->eq(0); -     } - -     /** -      * Retrieve a new Dom collection where the set of matched elements is reduced to the last in the set. -      * If the collection is empty a new empty collection is returned. -      * -      * @return Dom -      */ -     public function last(): Dom -     { -         return $this->eq(count($this) - 1); -     } - -     /** -      * Get a new Dom collection with the immediate child nodes of each of the Element nodes in the collection. -      * -      * @return Dom -      */ -     public function children(): Dom -     { -         $dom = new Dom(); - -         /** @var NodeInterface $node */ -         foreach ($this->nodes as $node) { -             if (!$node instanceof Element) { -                 continue; -             } - -             /** @var NodeInterface $child */ -             foreach ($node as $child) { -                 $dom->add($child); -             } -         } - -         return $dom; -     } - -     /** -      * Insert content after all immediate child nodes of each Element node in the collection. -      * -      * If any node derived from the content already has a parent node, a cloned copy will be used instead and it will -      * be assigned a new parent node. This means that, if appended to more than one Element node, references to each -      * appended node will only point to the very first insertion. -      * -      * E.g. if the same node is appended to two or more Element nodes, its reference will point to the node with the -      * first Element as parent. Nodes appended to all other Element nodes will be cloned copies. The same rule applies -      * to child nodes of appended nodes, at any depth, as the whole sub-tree is cloned recursively. -      * -      * @param $content -      * @return Dom -      */ -     public function append($content): Dom -     { -         $nodes = (new static($content))->nodes; - -         /** @var NodeInterface $node */ -         foreach ($this->nodes as $node) { -             if (!$node instanceof Element) { -                 continue; -             } - -             /** @var NodeInterface $child */ -             foreach ($nodes as $child) { -                 $node->insertAfter(null === $child->parent() ? $child : $child->clone()); -             } -         } - -         return $this; -     } - -     /** -      * Insert content before all immediate child nodes of each Element node in the collection. -      * -      * If any node derived from the content already has a parent node, a cloned copy will be used instead and it will -      * be assigned a new parent node. This means that, if prepended to more than one Element node, references to each -      * prepended node will only point to the very first insertion. -      * -      * E.g. if the same node is prepended to two or more Element nodes, its reference will point to the node with the -      * first Element as parent. Nodes prepended to all other Element nodes will be cloned copies. The same rule applies -      * to child nodes of prepended nodes, at any depth, as the whole sub-tree is cloned recursively. -      * -      * If the supplied content resolves to a collection of nodes, they will be prepended as a group, keeping the order. +         $count = count($this); + +         if ($index < 0 || $index >= $count) { +             throw new \OutOfBoundsException(sprintf( +                 'The requested node index %d is out of the collection bounds [%s].', +                 $index, +                 0 < $count ? '[0; ' . ($count - 1) . ']' : '(empty collection)' +             )); +         } + +         return $this->nodes[$index]; +     } + +     /** +      * Add the specified content to the end of the collection. +      * +      * @param $content +      * @return Dom +      */ +     public function add($content): Dom +     { +         /** @var NodeInterface $node */ +         foreach ((new static($content))->nodes as $node) { +             if (!in_array($node, $this->nodes, true)) { +                 $this->nodes[] = $node; +             } +         } + +         return $this; +     } + +     /** +      * Clear the collection. +      * +      * @return Dom +      */ +     public function clear(): Dom +     { +         $this->nodes = []; +         return $this; +     } + +     /** +      * Retrieve a new Dom collection where the set of matched elements is reduced to the one at the specified index. +      * If the specified index is out of bounds an empty collection is returned. +      * +      * @param int $index +      * @return Dom +      */ +     public function eq(int $index): Dom +     { +         return array_key_exists($index, $this->nodes) ? +             new static($this->nodes[$index]) : +             new static(); +     } + +     /** +      * Retrieve a new Dom collection where the set of matched elements is reduced to the first in the set. +      * If the collection is empty a new empty collection is returned. +      * +      * @return Dom +      */ +     public function first(): Dom +     { +         return $this->eq(0); +     } + +     /** +      * Retrieve a new Dom collection where the set of matched elements is reduced to the last in the set. +      * If the collection is empty a new empty collection is returned. +      * +      * @return Dom +      */ +     public function last(): Dom +     { +         return $this->eq(count($this) - 1); +     } + +     /** +      * Get a new Dom collection with the immediate child nodes of each of the Element nodes in the collection. +      * +      * @return Dom +      */ +     public function children(): Dom +     { +         $dom = new Dom(); + +         /** @var NodeInterface $node */ +         foreach ($this->nodes as $node) { +             if (!$node instanceof Element) { +                 continue; +             } + +             /** @var NodeInterface $child */ +             foreach ($node as $child) { +                 $dom->add($child); +             } +         } + +         return $dom; +     } + +     /** +      * Insert content after all immediate child nodes of each Element node in the collection. +      * +      * If any node derived from the content already has a parent node, a cloned copy will be used instead and it will +      * be assigned a new parent node. This means that, if appended to more than one Element node, references to each +      * appended node will only point to the very first insertion. +      * +      * E.g. if the same node is appended to two or more Element nodes, its reference will point to the node with the +      * first Element as parent. Nodes appended to all other Element nodes will be cloned copies. The same rule applies +      * to child nodes of appended nodes, at any depth, as the whole sub-tree is cloned recursively. +      * +      * @param $content +      * @return Dom +      */ +     public function append($content): Dom +     { +         $nodes = (new static($content))->nodes; + +         /** @var NodeInterface $node */ +         foreach ($this->nodes as $node) { +             if (!$node instanceof Element) { +                 continue; +             } + +             /** @var NodeInterface $child */ +             foreach ($nodes as $child) { +                 $node->insertAfter(null === $child->parent() ? $child : $child->clone()); +             } +         } + +         return $this; +     } + +     /** +      * Insert content before all immediate child nodes of each Element node in the collection. +      * +      * If any node derived from the content already has a parent node, a cloned copy will be used instead and it will +      * be assigned a new parent node. This means that, if prepended to more than one Element node, references to each +      * prepended node will only point to the very first insertion. +      * +      * E.g. if the same node is prepended to two or more Element nodes, its reference will point to the node with the +      * first Element as parent. Nodes prepended to all other Element nodes will be cloned copies. The same rule applies +      * to child nodes of prepended nodes, at any depth, as the whole sub-tree is cloned recursively.      * -      * @param $content -      * @return Dom -      */ -     public function prepend($content): Dom -     { -         $nodes = array_reverse((new static($content))->nodes); - -         /** @var NodeInterface $node */ -         foreach ($this->nodes as $node) { -             if (!$node instanceof Element) { -                 continue; -             } - -             /** @var NodeInterface $child */ -             foreach ($nodes as $child) { -                 $node->insertBefore(null === $child->parent() ? $child : $child->clone()); -             } -         } - -         return $this; -     } - -     /** -      * Insert content before each Element node in the collection. If an element in the collection does not have a -      * parent node it will be skipped / ignored. -      * -      * If any node derived from the content already has a parent node, a cloned copy will be used instead and it will -      * be assigned a new parent node. This means that, if inserted before more than one Element node, references to -      * each inserted node will only point to the very first successful insertion. -      * -      * E.g. if the same node is inserted before two or more Element nodes, its reference will point to the node -      * inserted before the first eligible Element in the collection (an Element without a parent node is not eligible -      * and will be ignored). Nodes inserted before all other Element nodes will be cloned copies. The same rule applies -      * to child nodes of inserted nodes, at any depth, as the whole sub-tree is cloned recursively. -      * -      * @param $content -      * @return Dom -      */ -     public function before($content): Dom -     { -         /** @var NodeInterface $node */ -         foreach ($this->nodes as $node) { -             if (!$node instanceof Element || null === $node->parent()) { -                 continue; -             } - -             /** @var Element $parent */ -             $parent = $node->parent(); - -             /** @var NodeInterface $child */ -             foreach (array_reverse((new static($content))->nodes) as $child) { -                 $parent->insertBefore(null === $child->parent() ? $child : $child->clone(), $node); -             } -         } - -         return $this; -     } - -     /** -      * Insert content after each Element node in the collection. If an element in the collection does not have a -      * parent node it will be skipped / ignored. -      * -      * If any node derived from the content already has a parent node, a cloned copy will be used instead and it will -      * be assigned a new parent node. This means that, if inserted after more than one Element node, references to -      * each inserted node will only point to the very first successful insertion. -      * -      * E.g. if the same node is inserted after two or more Element nodes, its reference will point to the node -      * inserted after the first eligible Element in the collection (an Element without a parent node is not eligible -      * and will be ignored). Nodes inserted after all other Element nodes will be cloned copies. The same rule applies -      * to child nodes of inserted nodes, at any depth, as the whole sub-tree is cloned recursively. -      * -      * @param $content -      * @return Dom -      */ -     public function after($content): Dom -     { -         /** @var NodeInterface $node */ -         foreach ($this->nodes as $node) { -             if (!$node instanceof Element || null === $node->parent()) { -                 continue; -             } - -             /** @var Element $parent */ -             $parent = $node->parent(); - -             /** @var NodeInterface $child */ -             foreach (array_reverse((new static($content))->nodes) as $child) { -                 $parent->insertAfter(null === $child->parent() ? $child : $child->clone(), $node); -             } -         } - -         return $this; -     } - -     /** -      * Wrap a clone of the supplied content around each node with a parent (not only element nodes) in the collection. -      * -      * If the content resolves to a collection of more than one wrapping element node, use only the first one. -      * If the wrapping element has children use a single-element-per-level sub-tree, where the wrapping element is -      * the root and may contain one and only one element node, which may contain another one and only one element node -      * and so on. -      * -      * Wrap the current collection nodes in clones of this sub-tree as immediate children of the inner-most element -      * node of the tree. If a node in the collection does not have a parent element, ignore it. -      * -      * If the wrapping collection does not contain at least one element node, do nothing. +      * If the supplied content resolves to a collection of nodes, they will be prepended as a group, keeping the order. +      * +      * @param $content +      * @return Dom +      */ +     public function prepend($content): Dom +     { +         $nodes = array_reverse((new static($content))->nodes); + +         /** @var NodeInterface $node */ +         foreach ($this->nodes as $node) { +             if (!$node instanceof Element) { +                 continue; +             } + +             /** @var NodeInterface $child */ +             foreach ($nodes as $child) { +                 $node->insertBefore(null === $child->parent() ? $child : $child->clone()); +             } +         } + +         return $this; +     } + +     /** +      * Insert content before each Element node in the collection. If an element in the collection does not have a +      * parent node it will be skipped / ignored. +      * +      * If any node derived from the content already has a parent node, a cloned copy will be used instead and it will +      * be assigned a new parent node. This means that, if inserted before more than one Element node, references to +      * each inserted node will only point to the very first successful insertion. +      * +      * E.g. if the same node is inserted before two or more Element nodes, its reference will point to the node +      * inserted before the first eligible Element in the collection (an Element without a parent node is not eligible +      * and will be ignored). Nodes inserted before all other Element nodes will be cloned copies. The same rule applies +      * to child nodes of inserted nodes, at any depth, as the whole sub-tree is cloned recursively. +      * +      * @param $content +      * @return Dom +      */ +     public function before($content): Dom +     { +         /** @var NodeInterface $node */ +         foreach ($this->nodes as $node) { +             if (!$node instanceof Element || null === $node->parent()) { +                 continue; +             } + +             /** @var Element $parent */ +             $parent = $node->parent(); + +             /** @var NodeInterface $child */ +             foreach (array_reverse((new static($content))->nodes) as $child) { +                 $parent->insertBefore(null === $child->parent() ? $child : $child->clone(), $node); +             } +         } + +         return $this; +     } + +     /** +      * Insert content after each Element node in the collection. If an element in the collection does not have a +      * parent node it will be skipped / ignored. +      * +      * If any node derived from the content already has a parent node, a cloned copy will be used instead and it will +      * be assigned a new parent node. This means that, if inserted after more than one Element node, references to +      * each inserted node will only point to the very first successful insertion. +      * +      * E.g. if the same node is inserted after two or more Element nodes, its reference will point to the node +      * inserted after the first eligible Element in the collection (an Element without a parent node is not eligible +      * and will be ignored). Nodes inserted after all other Element nodes will be cloned copies. The same rule applies +      * to child nodes of inserted nodes, at any depth, as the whole sub-tree is cloned recursively. +      * +      * @param $content +      * @return Dom +      */ +     public function after($content): Dom +     { +         /** @var NodeInterface $node */ +         foreach ($this->nodes as $node) { +             if (!$node instanceof Element || null === $node->parent()) { +                 continue; +             } + +             /** @var Element $parent */ +             $parent = $node->parent(); + +             /** @var NodeInterface $child */ +             foreach (array_reverse((new static($content))->nodes) as $child) { +                 $parent->insertAfter(null === $child->parent() ? $child : $child->clone(), $node); +             } +         } + +         return $this; +     } + +     /** +      * Wrap a clone of the supplied content around each node with a parent (not only element nodes) in the collection. +      * +      * If the content resolves to a collection of more than one wrapping element node, use only the first one. +      * If the wrapping element has children use a single-element-per-level sub-tree, where the wrapping element is +      * the root and may contain one and only one element node, which may contain another one and only one element node +      * and so on. +      * +      * Wrap the current collection nodes in clones of this sub-tree as immediate children of the inner-most element +      * node of the tree. If a node in the collection does not have a parent element, ignore it.      * -      * Return the original collection for chaining. +      * If the wrapping collection does not contain at least one element node, do nothing.      * -      * @param $content -      * @return Dom -      */ -     public function wrap($content): Dom -     { -         // get a detached clone of the first element node in the content -         /** @var Element $wrapper */ -         $wrapper = static::findFirstElement((new static($content))->nodes); -         if (!$wrapper) { -             return $this; -         } -         $wrapper = $wrapper->clone()->detach(); - -         // collapse the wrapper down to a single-element-per-level tree of clones -         $inner = $wrapper; -         while (0 < count($inner)) { -             $element = static::findFirstElement($inner->getIterator()->getArrayCopy()); -             if (!$element) { -                 break; -             } -             $inner->clear()->insertAfter($inner = $element->clone()); -         } - -         // wrap nodes -         foreach ($this->nodes as $node) { -             if (null === $node->parent()) { -                 continue; -             } - -             /** @var Element $insert */ -             $insert = $wrapper->clone(); - -             /** @var Element $parent */ -             $parent = $node->parent(); -             $parent->insertAfter($insert, $node); - -             $inner = static::findFirstInnermostElement($insert->getIterator()->getArrayCopy()); +      * Return the original collection for chaining. +      * +      * @param $content +      * @return Dom +      */ +     public function wrap($content): Dom +     { +         // get a detached clone of the first element node in the content +         /** @var Element $wrapper */ +         $wrapper = static::findFirstElement((new static($content))->nodes); +         if (!$wrapper) { +             return $this; +         } +         $wrapper = $wrapper->clone()->detach(); + +         // collapse the wrapper down to a single-element-per-level tree of clones +         $inner = $wrapper; +         while (0 < count($inner)) { +             $element = static::findFirstElement($inner->getIterator()->getArrayCopy()); +             if (!$element) { +                 break; +             } +             $inner->clear()->insertAfter($inner = $element->clone()); +         } + +         // wrap nodes +         foreach ($this->nodes as $node) { +             if (null === $node->parent()) { +                 continue; +             } + +             /** @var Element $insert */ +             $insert = $wrapper->clone(); + +             /** @var Element $parent */ +             $parent = $node->parent(); +             $parent->insertAfter($insert, $node); -             if ($inner) { -                 $inner->insertAfter($node); -             } else { -                 $insert->insertAfter($node); -             } -         } - -         return $this; -     } - -     /** -      * Wrap a clone of the supplied content around each child node (not only element nodes) of nodes in the collection. -      * -      * This function works exactly like wrap() except it wraps the children of the nodes in the collection instead. +             $inner = static::findFirstInnermostElement($insert->getIterator()->getArrayCopy()); + +             if ($inner) { +                 $inner->insertAfter($node); +             } else { +                 $insert->insertAfter($node); +             } +         } + +         return $this; +     } + +     /** +      * Wrap a clone of the supplied content around each child node (not only element nodes) of nodes in the collection.      * -      * Return the original collection for chaining. +      * This function works exactly like wrap() except it wraps the children of the nodes in the collection instead.      * -      * @param $content -      * @return Dom -      */ -     public function wrapInner($content): Dom -     { -         foreach ($this->children() as $child) { -             $child->wrap($content); -         } -         return $this; -     } - -     /** -      * Return a new Dom collection of all the descendants of each Element node in the current collection, -      * filtered by the specified CSS selector. -      * -      * @param string $selector -      * @return Dom -      */ -     public function find(string $selector): Dom -     { -         if (!isset(self::$selectorParser)) { -             self::$selectorParser = new Parser(); -         } - -         if (!isset(self::$selectorMatcher)) { -             self::$selectorMatcher = new SelectorMatcher(); -         } - -         $dom = new static(); -         $selectorTokens = self::$selectorParser->parse($selector); - -         foreach ($this->get() as $rootNode) { -             /** @var NodeInterface $childNode */ -             foreach ($rootNode as $childNode) { -                 self::traverseMatch($dom, $selectorTokens, $childNode, $rootNode); -             } -         } - -         return $dom; -     } - -     /** -      * Adds the specified class(es) to each Element node in the collection. -      * -      * @param string $className -      * @return Dom -      */ -     public function addClass(string $className): Dom -     { -         $className = trim($className); - -         // bail if no classes to add -         if ('' === $className) { -             return $this; -         } - -         $addClasses = preg_split('/\s+/', $className); +      * Return the original collection for chaining. +      * +      * @param $content +      * @return Dom +      */ +     public function wrapInner($content): Dom +     { +         foreach ($this->children() as $child) { +             $child->wrap($content); +         } +         return $this; +     } + +     /** +      * Return a new Dom collection of all the descendants of each Element node in the current collection, +      * filtered by the specified CSS selector. +      * +      * @param string $selector +      * @return Dom +      */ +     public function find(string $selector): Dom +     { +         if (!isset(self::$selectorParser)) { +             self::$selectorParser = new Parser(); +         } + +         if (!isset(self::$selectorMatcher)) { +             self::$selectorMatcher = new SelectorMatcher(); +         } + +         $dom = new static(); +         $selectorTokens = self::$selectorParser->parse($selector); + +         foreach ($this->get() as $rootNode) { +             /** @var NodeInterface $childNode */ +             foreach ($rootNode as $childNode) { +                 self::traverseMatch($dom, $selectorTokens, $childNode, $rootNode); +             } +         } + +         return $dom; +     } + +     /** +      * Adds the specified class(es) to each Element node in the collection. +      * +      * @param string $className +      * @return Dom +      */ +     public function addClass(string $className): Dom +     { +         $className = trim($className); + +         // bail if no classes to add +         if ('' === $className) { +             return $this; +         } -         /** @var NodeInterface $node */ -         foreach ($this->nodes as $node) { -             if (!$node instanceof Element) { -                 continue; -             } - -             // if the node already has a "class" attribute, merge all classes & make sure the result is unique -             if ($node->hasAttribute('class')) { -                 $currentClassName = trim($node->getAttribute('class')); -                 $currentClasses = '' === $currentClassName ? [] : preg_split('/\s+/', $currentClassName); -                 $node->setAttribute('class', implode(' ', array_unique(array_merge($currentClasses, $addClasses)))); -             } - -             // if the node does not have a "class" attribute, directly set the new ones -             else { -                 $node->setAttribute('class', implode(' ', $addClasses)); -             } -         } - -         return $this; -     } - -     /** -      * Remove a single class, multiple classes, or all classes from each Element node in the collection. -      * -      * @param string|null $className -      * @return Dom -      */ -     public function removeClass(string $className = null): Dom -     { -         // if class to remove isn't set, remove all classes, but keep the "class" attribute present -         if (!isset($className)) { -             /** @var NodeInterface $node */ -             foreach ($this->nodes as $node) { -                 if (!$node instanceof Element || !$node->hasAttribute('class')) { -                     continue; -                 } - -                 $node->setAttribute('class', ''); -             } - -             return $this; -         } - -         $removeClasses = preg_split('/\s+/', $className); +         $addClasses = preg_split('/\s+/', $className); + +         /** @var NodeInterface $node */ +         foreach ($this->nodes as $node) { +             if (!$node instanceof Element) { +                 continue; +             } + +             // if the node already has a "class" attribute, merge all classes & make sure the result is unique +             if ($node->hasAttribute('class')) { +                 $currentClassName = trim($node->getAttribute('class')); +                 $currentClasses = '' === $currentClassName ? [] : preg_split('/\s+/', $currentClassName); +                 $node->setAttribute('class', implode(' ', array_unique(array_merge($currentClasses, $addClasses)))); +             } + +             // if the node does not have a "class" attribute, directly set the new ones +             else { +                 $node->setAttribute('class', implode(' ', $addClasses)); +             } +         } + +         return $this; +     } + +     /** +      * Remove a single class, multiple classes, or all classes from each Element node in the collection. +      * +      * @param string|null $className +      * @return Dom +      */ +     public function removeClass(string $className = null): Dom +     { +         // if class to remove isn't set, remove all classes, but keep the "class" attribute present +         if (!isset($className)) { +             /** @var NodeInterface $node */ +             foreach ($this->nodes as $node) { +                 if (!$node instanceof Element || !$node->hasAttribute('class')) { +                     continue; +                 } + +                 $node->setAttribute('class', ''); +             } + +             return $this; +         } -         /** @var NodeInterface $node */ -         foreach ($this->nodes as $node) { -             if (!$node instanceof Element || !$node->hasAttribute('class')) { -                 continue; -             } - -             // set to the difference between the current classes and the remove ones -             $currentClasses = preg_split('/\s+/', $node->getAttribute('class')); -             $node->setAttribute('class', implode(' ', array_diff($currentClasses, $removeClasses))); -         } - -         return $this; -     } - -     /** -      * Return TRUE if at least one of the Element nodes in the collection has the specified class assigned. -      * -      * @param string $className -      * @return bool -      */ -     public function hasClass(string $className): bool -     { -         /** @var NodeInterface $node */ -         foreach ($this->nodes as $node) { -             if (!$node instanceof Element || !$node->hasAttribute('class')) { -                 continue; -             } - -             if (SelectorMatcher::containsWord($className, $node->getAttribute('class'))) { -                 return true; -             } -         } - -         return false; -     } - -     /** -      * Get the value of an attribute for the first Element node in the collection. -      * Set the value of an attribute for each Element node in the collection. -      * -      * @param string $name -      * @param string|null $value -      * @return string|null|$this -      */ -     public function attr(string $name, string $value = null) -     { -         if (isset($value)) { -             /** @var NodeInterface $node */ -             foreach ($this->nodes as $node) { -                 if (!$node instanceof Element) { -                     continue; -                 } - -                 $node->setAttribute($name, $value); -             } - -             return $this; -         } - -         /** @var NodeInterface $node */ -         foreach ($this->nodes as $node) { -             if (!$node instanceof Element) { -                 continue; -             } - -             return $node->getAttribute($name); -         } - -         return null; -     } - -     /** -      * Remove an attribute from each Element node in the collection. -      * -      * @param string $name -      * @return Dom -      */ -     public function removeAttr(string $name): Dom -     { -         /** @var NodeInterface $node */ -         foreach ($this->nodes as $node) { -             if (!$node instanceof Element) { -                 continue; -             } - -             $node->removeAttribute($name); -         } - -         return $this; -     } - -     /** -      * Get the combined text contents of each Element node in the collection, including their descendants. -      * Set the content of each Element node in the collection to the specified text. -      * -      * @param string|null $text -      * @return $this|string -      */ -     public function text(string $text = null) -     { -         if (isset($text)) { -             foreach ($this->nodes as $node) { -                 if (!$node instanceof Element) { -                     continue; -                 } - -                 $node->clear()->insertAfter(new Text($text)); -             } - -             return $this; -         } - -         $text = ''; +         $removeClasses = preg_split('/\s+/', $className); + +         /** @var NodeInterface $node */ +         foreach ($this->nodes as $node) { +             if (!$node instanceof Element || !$node->hasAttribute('class')) { +                 continue; +             } + +             // set to the difference between the current classes and the remove ones +             $currentClasses = preg_split('/\s+/', $node->getAttribute('class')); +             $node->setAttribute('class', implode(' ', array_diff($currentClasses, $removeClasses))); +         } + +         return $this; +     } + +     /** +      * Return TRUE if at least one of the Element nodes in the collection has the specified class assigned. +      * +      * @param string $className +      * @return bool +      */ +     public function hasClass(string $className): bool +     { +         /** @var NodeInterface $node */ +         foreach ($this->nodes as $node) { +             if (!$node instanceof Element || !$node->hasAttribute('class')) { +                 continue; +             } + +             if (SelectorMatcher::containsWord($className, $node->getAttribute('class'))) { +                 return true; +             } +         } + +         return false; +     } + +     /** +      * Get the value of an attribute for the first Element node in the collection. +      * Set the value of an attribute for each Element node in the collection. +      * +      * @param string $name +      * @param string|null $value +      * @return string|null|$this +      */ +     public function attr(string $name, string $value = null) +     { +         if (isset($value)) { +             /** @var NodeInterface $node */ +             foreach ($this->nodes as $node) { +                 if (!$node instanceof Element) { +                     continue; +                 } + +                 $node->setAttribute($name, $value); +             } + +             return $this; +         } + +         /** @var NodeInterface $node */ +         foreach ($this->nodes as $node) { +             if (!$node instanceof Element) { +                 continue; +             } + +             return $node->getAttribute($name); +         } + +         return null; +     } + +     /** +      * Remove an attribute from each Element node in the collection. +      * +      * @param string $name +      * @return Dom +      */ +     public function removeAttr(string $name): Dom +     { +         /** @var NodeInterface $node */ +         foreach ($this->nodes as $node) { +             if (!$node instanceof Element) { +                 continue; +             } + +             $node->removeAttribute($name); +         } + +         return $this; +     } + +     /** +      * Get the combined text contents of each Element node in the collection, including their descendants. +      * Set the content of each Element node in the collection to the specified text. +      * +      * @param string|null $text +      * @return $this|string +      */ +     public function text(string $text = null) +     { +         if (isset($text)) { +             foreach ($this->nodes as $node) { +                 if (!$node instanceof Element) { +                     continue; +                 } + +                 $node->clear()->insertAfter(new Text($text)); +             } + +             return $this; +         } -         foreach ($this->nodes as $node) { -             if ($node instanceof Text) { -                 $text .= (string) $node; -             } else if ($node instanceof Element) { -                 /** @var Dom $dom */ -                 foreach ((new static($node))->children() as $dom) { -                     $text .= $dom->text(); -                 } -             } -         } - -         return $text; -     } - -     /** -      * Get the HTML contents of the first Element node in the collection. -      * Set the HTML contents of each Element node in the collection. -      * -      * @param string|null $html -      * @return $this|string -      */ -     public function html(string $html = null) -     { -         if (isset($html)) { -             foreach ($this->nodes as $node) { -                 if (!$node instanceof Element) { -                     continue; -                 } - -                 $node->clear(); +         $text = ''; + +         foreach ($this->nodes as $node) { +             if ($node instanceof Text) { +                 $text .= (string) $node; +             } else if ($node instanceof Element) { +                 /** @var Dom $dom */ +                 foreach ((new static($node))->children() as $dom) { +                     $text .= $dom->text(); +                 } +             } +         } + +         return $text; +     } + +     /** +      * Get the HTML contents of the first Element node in the collection. +      * Set the HTML contents of each Element node in the collection. +      * +      * @param string|null $html +      * @return $this|string +      */ +     public function html(string $html = null) +     { +         if (isset($html)) { +             foreach ($this->nodes as $node) { +                 if (!$node instanceof Element) { +                     continue; +                 } -                 foreach ((new static($html))->nodes as $newNode) { -                     $node->insertAfter($newNode); -                 } -             } - -             return $this; -         } - -         foreach ($this->nodes as $node) { -             if (!$node instanceof Element) { -                 continue; -             } - -             $html = ''; +                 $node->clear(); + +                 foreach ((new static($html))->nodes as $newNode) { +                     $node->insertAfter($newNode); +                 } +             } + +             return $this; +         } + +         foreach ($this->nodes as $node) { +             if (!$node instanceof Element) { +                 continue; +             } -             /** @var NodeInterface $childNode */ -             foreach ($node as $childNode) { -                 $html .= (string) $childNode; -             } - -             return $html; -         } - -         return ''; -     } - } +             $html = ''; + +             /** @var NodeInterface $childNode */ +             foreach ($node as $childNode) { +                 $html .= (string) $childNode; +             } + +             return $html; +         } + +         return ''; +     } + } @@ -1648,7 +1650,7 @@

Legend

Dead Code

- Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:08:03 EEST 2018. + Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:43:17 EEST 2018.

diff --git a/docs/coverage/Node/CData.php.html b/docs/coverage/Node/CData.php.html index f64f67b..3655d82 100644 --- a/docs/coverage/Node/CData.php.html +++ b/docs/coverage/Node/CData.php.html @@ -374,7 +374,7 @@

Legend

Dead Code

- Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:08:03 EEST 2018. + Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:43:17 EEST 2018.

diff --git a/docs/coverage/Node/Comment.php.html b/docs/coverage/Node/Comment.php.html index 01c1213..3d2dec1 100644 --- a/docs/coverage/Node/Comment.php.html +++ b/docs/coverage/Node/Comment.php.html @@ -374,7 +374,7 @@

Legend

Dead Code

- Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:08:03 EEST 2018. + Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:43:17 EEST 2018.

diff --git a/docs/coverage/Node/DocType.php.html b/docs/coverage/Node/DocType.php.html index bcd1895..b47f265 100644 --- a/docs/coverage/Node/DocType.php.html +++ b/docs/coverage/Node/DocType.php.html @@ -346,7 +346,7 @@

Legend

Dead Code

- Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:08:03 EEST 2018. + Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:43:17 EEST 2018.

diff --git a/docs/coverage/Node/Element.php.html b/docs/coverage/Node/Element.php.html index 9e8afb7..18772bb 100644 --- a/docs/coverage/Node/Element.php.html +++ b/docs/coverage/Node/Element.php.html @@ -67,7 +67,7 @@
100.00%
-
90 / 90
+
91 / 91
@@ -96,7 +96,7 @@
100.00%
-
90 / 90
+
91 / 91
@@ -432,11 +432,11 @@
100.00%
-
7 / 7
+
8 / 8
-  isChild +  isChild
100.00% covered (success) @@ -457,7 +457,7 @@ -  get +  get
100.00% covered (success) @@ -478,7 +478,7 @@ -  index +  index
100.00% covered (success) @@ -499,7 +499,7 @@ -  removeChild +  removeChild
100.00% covered (success) @@ -520,7 +520,7 @@ -  clear +  clear
100.00% covered (success) @@ -541,7 +541,7 @@ -  isVoid +  isVoid
100.00% covered (success) @@ -872,111 +872,112 @@             if (false === $index) {                 throw new \InvalidArgumentException('Only immediate child nodes can be used as insertBefore anchor.');             } -         } - -         array_splice($this->children, $index, 0, [$node->attach($this)]); -         return $this; -     } - -     /** -      * Returns TRUE if the specified node is an immediate child of the current node. -      * -      * @param NodeInterface $node -      * @return bool -      */ -     public function isChild(NodeInterface $node): bool -     { -         return in_array($node, $this->children); -     } - -     /** -      * Retrieve a NodeInterface instance (immediate child node) for the specified index. -      * Throw \OutOfBoundsException exception if the specified index is out of bounds. -      * -      * @param int $index -      * @return NodeInterface -      * @throws \OutOfBoundsException -      */ -     public function get(int $index): NodeInterface -     { -         $count = count($this); - -         if ($index < 0 || $index >= $count) { -             throw new \OutOfBoundsException(sprintf( -                 'The requested node index %d is out of the child list bounds [%s].', -                 $index, -                 0 < $count ? '[0; ' . ($count - 1) . ']' : '(empty child list)' -             )); -         } - -         return $this->children[$index]; -     } - -     /** -      * Retrieve the positional index of the specified NodeInterface in the list of immediate child nodes. -      * If the target node is not an immediate child node of this one, an exception will be thrown. -      * -      * @param NodeInterface $node -      * @return int -      * @throws \InvalidArgumentException -      */ -     public function index(NodeInterface $node): int -     { -         $index = array_search($node, $this->children, true); -         if (false === $index) { -             throw new \InvalidArgumentException('The specified node is not an immediate child node.'); -         } - -         return $index; -     } - -     /** -      * Remove the specified node from the list of immediate children of this node. -      * If the target node is not an immediate child node of this one, an exception will be thrown. -      * The node's detach() method will also be called to release the parent reference if such is set. -      * -      * @param NodeInterface $node -      * @return Element -      */ -     public function removeChild(NodeInterface $node): Element -     { -         $index = $this->index($node); -         $child = $this->children[$index]; - -         array_splice($this->children, $index, 1); - -         if (null !== $child->parent()) { -             $child->detach(); -         } - -         return $this; -     } - -     /** -      * Remove all child nodes. -      * -      * @return Element -      */ -     public function clear(): Element -     { -         /** @var NodeInterface $node */ -         foreach ($this as $node) { -             $this->removeChild($node); -         } - -         return $this; -     } - -     /** -      * Returns TRUE if the element's tag matches the list of void element tags. -      * -      * @return bool -      */ -     public function isVoid(): bool -     { -         return in_array($this->tag, static::$void); -     } - } +             $index = (int) $index; +         } + +         array_splice($this->children, $index, 0, [$node->attach($this)]); +         return $this; +     } + +     /** +      * Returns TRUE if the specified node is an immediate child of the current node. +      * +      * @param NodeInterface $node +      * @return bool +      */ +     public function isChild(NodeInterface $node): bool +     { +         return in_array($node, $this->children); +     } + +     /** +      * Retrieve a NodeInterface instance (immediate child node) for the specified index. +      * Throw \OutOfBoundsException exception if the specified index is out of bounds. +      * +      * @param int $index +      * @return NodeInterface +      * @throws \OutOfBoundsException +      */ +     public function get(int $index): NodeInterface +     { +         $count = count($this); + +         if ($index < 0 || $index >= $count) { +             throw new \OutOfBoundsException(sprintf( +                 'The requested node index %d is out of the child list bounds [%s].', +                 $index, +                 0 < $count ? '[0; ' . ($count - 1) . ']' : '(empty child list)' +             )); +         } + +         return $this->children[$index]; +     } + +     /** +      * Retrieve the positional index of the specified NodeInterface in the list of immediate child nodes. +      * If the target node is not an immediate child node of this one, an exception will be thrown. +      * +      * @param NodeInterface $node +      * @return int +      * @throws \InvalidArgumentException +      */ +     public function index(NodeInterface $node): int +     { +         $index = array_search($node, $this->children, true); +         if (false === $index) { +             throw new \InvalidArgumentException('The specified node is not an immediate child node.'); +         } + +         return $index; +     } + +     /** +      * Remove the specified node from the list of immediate children of this node. +      * If the target node is not an immediate child node of this one, an exception will be thrown. +      * The node's detach() method will also be called to release the parent reference if such is set. +      * +      * @param NodeInterface $node +      * @return Element +      */ +     public function removeChild(NodeInterface $node): Element +     { +         $index = $this->index($node); +         $child = $this->children[$index]; + +         array_splice($this->children, $index, 1); + +         if (null !== $child->parent()) { +             $child->detach(); +         } + +         return $this; +     } + +     /** +      * Remove all child nodes. +      * +      * @return Element +      */ +     public function clear(): Element +     { +         /** @var NodeInterface $node */ +         foreach ($this as $node) { +             $this->removeChild($node); +         } + +         return $this; +     } + +     /** +      * Returns TRUE if the element's tag matches the list of void element tags. +      * +      * @return bool +      */ +     public function isVoid(): bool +     { +         return in_array($this->tag, static::$void); +     } + } @@ -989,7 +990,7 @@

Legend

Dead Code

- Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:08:03 EEST 2018. + Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:43:17 EEST 2018.

diff --git a/docs/coverage/Node/NodeInterface.php.html b/docs/coverage/Node/NodeInterface.php.html index ed5ea48..29fadd3 100644 --- a/docs/coverage/Node/NodeInterface.php.html +++ b/docs/coverage/Node/NodeInterface.php.html @@ -137,7 +137,7 @@

Legend

Dead Code

- Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:08:03 EEST 2018. + Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:43:17 EEST 2018.

diff --git a/docs/coverage/Node/Text.php.html b/docs/coverage/Node/Text.php.html index 1fa9c58..b8b9922 100644 --- a/docs/coverage/Node/Text.php.html +++ b/docs/coverage/Node/Text.php.html @@ -377,7 +377,7 @@

Legend

Dead Code

- Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:08:03 EEST 2018. + Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:43:17 EEST 2018.

diff --git a/docs/coverage/Node/dashboard.html b/docs/coverage/Node/dashboard.html index c6ac53e..c278795 100644 --- a/docs/coverage/Node/dashboard.html +++ b/docs/coverage/Node/dashboard.html @@ -137,7 +137,7 @@

Project Risks

@@ -250,7 +250,7 @@

Project Risks

chart.yAxis.axisLabel('Method Complexity'); d3.select('#methodComplexity svg') - .datum(getComplexityData([[100,1,"SDom\\Node\\CData::__construct<\/a>"],[100,1,"SDom\\Node\\CData::__toString<\/a>"],[100,1,"SDom\\Node\\CData::__clone<\/a>"],[100,2,"SDom\\Node\\CData::parent<\/a>"],[100,4,"SDom\\Node\\CData::attach<\/a>"],[100,3,"SDom\\Node\\CData::detach<\/a>"],[100,1,"SDom\\Node\\CData::clone<\/a>"],[100,1,"SDom\\Node\\Comment::__construct<\/a>"],[100,1,"SDom\\Node\\Comment::__toString<\/a>"],[100,1,"SDom\\Node\\Comment::__clone<\/a>"],[100,2,"SDom\\Node\\Comment::parent<\/a>"],[100,4,"SDom\\Node\\Comment::attach<\/a>"],[100,3,"SDom\\Node\\Comment::detach<\/a>"],[100,1,"SDom\\Node\\Comment::clone<\/a>"],[100,1,"SDom\\Node\\DocType::__construct<\/a>"],[100,1,"SDom\\Node\\DocType::__toString<\/a>"],[100,1,"SDom\\Node\\DocType::__clone<\/a>"],[100,2,"SDom\\Node\\DocType::parent<\/a>"],[100,1,"SDom\\Node\\DocType::attach<\/a>"],[100,1,"SDom\\Node\\DocType::detach<\/a>"],[100,1,"SDom\\Node\\DocType::clone<\/a>"],[100,1,"SDom\\Node\\Element::__construct<\/a>"],[100,5,"SDom\\Node\\Element::__toString<\/a>"],[100,1,"SDom\\Node\\Element::__clone<\/a>"],[100,1,"SDom\\Node\\Element::getTag<\/a>"],[100,1,"SDom\\Node\\Element::hasAttribute<\/a>"],[100,1,"SDom\\Node\\Element::setAttribute<\/a>"],[100,3,"SDom\\Node\\Element::getAttribute<\/a>"],[100,2,"SDom\\Node\\Element::removeAttribute<\/a>"],[100,2,"SDom\\Node\\Element::parent<\/a>"],[100,4,"SDom\\Node\\Element::attach<\/a>"],[100,3,"SDom\\Node\\Element::detach<\/a>"],[100,3,"SDom\\Node\\Element::clone<\/a>"],[100,1,"SDom\\Node\\Element::getIterator<\/a>"],[100,1,"SDom\\Node\\Element::count<\/a>"],[100,3,"SDom\\Node\\Element::insertAfter<\/a>"],[100,3,"SDom\\Node\\Element::insertBefore<\/a>"],[100,1,"SDom\\Node\\Element::isChild<\/a>"],[100,4,"SDom\\Node\\Element::get<\/a>"],[100,2,"SDom\\Node\\Element::index<\/a>"],[100,2,"SDom\\Node\\Element::removeChild<\/a>"],[100,2,"SDom\\Node\\Element::clear<\/a>"],[100,1,"SDom\\Node\\Element::isVoid<\/a>"],[100,1,"SDom\\Node\\Text::__construct<\/a>"],[100,1,"SDom\\Node\\Text::__toString<\/a>"],[100,1,"SDom\\Node\\Text::__clone<\/a>"],[100,2,"SDom\\Node\\Text::parent<\/a>"],[100,4,"SDom\\Node\\Text::attach<\/a>"],[100,3,"SDom\\Node\\Text::detach<\/a>"],[100,1,"SDom\\Node\\Text::clone<\/a>"]], 'Method Complexity')) + .datum(getComplexityData([[100,1,"SDom\\Node\\CData::__construct<\/a>"],[100,1,"SDom\\Node\\CData::__toString<\/a>"],[100,1,"SDom\\Node\\CData::__clone<\/a>"],[100,2,"SDom\\Node\\CData::parent<\/a>"],[100,4,"SDom\\Node\\CData::attach<\/a>"],[100,3,"SDom\\Node\\CData::detach<\/a>"],[100,1,"SDom\\Node\\CData::clone<\/a>"],[100,1,"SDom\\Node\\Comment::__construct<\/a>"],[100,1,"SDom\\Node\\Comment::__toString<\/a>"],[100,1,"SDom\\Node\\Comment::__clone<\/a>"],[100,2,"SDom\\Node\\Comment::parent<\/a>"],[100,4,"SDom\\Node\\Comment::attach<\/a>"],[100,3,"SDom\\Node\\Comment::detach<\/a>"],[100,1,"SDom\\Node\\Comment::clone<\/a>"],[100,1,"SDom\\Node\\DocType::__construct<\/a>"],[100,1,"SDom\\Node\\DocType::__toString<\/a>"],[100,1,"SDom\\Node\\DocType::__clone<\/a>"],[100,2,"SDom\\Node\\DocType::parent<\/a>"],[100,1,"SDom\\Node\\DocType::attach<\/a>"],[100,1,"SDom\\Node\\DocType::detach<\/a>"],[100,1,"SDom\\Node\\DocType::clone<\/a>"],[100,1,"SDom\\Node\\Element::__construct<\/a>"],[100,5,"SDom\\Node\\Element::__toString<\/a>"],[100,1,"SDom\\Node\\Element::__clone<\/a>"],[100,1,"SDom\\Node\\Element::getTag<\/a>"],[100,1,"SDom\\Node\\Element::hasAttribute<\/a>"],[100,1,"SDom\\Node\\Element::setAttribute<\/a>"],[100,3,"SDom\\Node\\Element::getAttribute<\/a>"],[100,2,"SDom\\Node\\Element::removeAttribute<\/a>"],[100,2,"SDom\\Node\\Element::parent<\/a>"],[100,4,"SDom\\Node\\Element::attach<\/a>"],[100,3,"SDom\\Node\\Element::detach<\/a>"],[100,3,"SDom\\Node\\Element::clone<\/a>"],[100,1,"SDom\\Node\\Element::getIterator<\/a>"],[100,1,"SDom\\Node\\Element::count<\/a>"],[100,3,"SDom\\Node\\Element::insertAfter<\/a>"],[100,3,"SDom\\Node\\Element::insertBefore<\/a>"],[100,1,"SDom\\Node\\Element::isChild<\/a>"],[100,4,"SDom\\Node\\Element::get<\/a>"],[100,2,"SDom\\Node\\Element::index<\/a>"],[100,2,"SDom\\Node\\Element::removeChild<\/a>"],[100,2,"SDom\\Node\\Element::clear<\/a>"],[100,1,"SDom\\Node\\Element::isVoid<\/a>"],[100,1,"SDom\\Node\\Text::__construct<\/a>"],[100,1,"SDom\\Node\\Text::__toString<\/a>"],[100,1,"SDom\\Node\\Text::__clone<\/a>"],[100,2,"SDom\\Node\\Text::parent<\/a>"],[100,4,"SDom\\Node\\Text::attach<\/a>"],[100,3,"SDom\\Node\\Text::detach<\/a>"],[100,1,"SDom\\Node\\Text::clone<\/a>"]], 'Method Complexity')) .transition() .duration(500) .call(chart); diff --git a/docs/coverage/Node/index.html b/docs/coverage/Node/index.html index d9b6dd4..bc408d1 100644 --- a/docs/coverage/Node/index.html +++ b/docs/coverage/Node/index.html @@ -50,7 +50,7 @@
100.00%
-
182 / 182
+
183 / 183
100.00% covered (success) @@ -162,7 +162,7 @@
100.00%
-
90 / 90
+
91 / 91
diff --git a/docs/coverage/SelectorMatcher.php.html b/docs/coverage/SelectorMatcher.php.html index 3a36134..af98188 100644 --- a/docs/coverage/SelectorMatcher.php.html +++ b/docs/coverage/SelectorMatcher.php.html @@ -66,7 +66,7 @@
100.00%
-
16 / 16
+
10 / 10
@@ -87,7 +87,7 @@
100.00%
2 / 2
- 8 + 9
100.00% covered (success) @@ -95,7 +95,7 @@
100.00%
-
16 / 16
+
10 / 10
@@ -108,7 +108,7 @@
100.00%
1 / 1
- 1 + 2
100.00% covered (success) @@ -120,7 +120,11 @@ -  match +  match
100.00% covered (success) @@ -137,7 +141,7 @@
100.00%
-
15 / 15
+
9 / 9
@@ -149,13 +153,13 @@ namespace SDom; - use SDom\Node as Dom; + use SDom\Node as DomNode; use SDom\SelectorMatcher\AttributeNodeTrait; use SDom\SelectorMatcher\ClassNodeTrait; use SDom\SelectorMatcher\CombinedSelectorNodeTrait; use SDom\SelectorMatcher\ElementNodeTrait; use SDom\SelectorMatcher\HashNodeTrait; - use Symfony\Component\CssSelector\Node as Css; + use Symfony\Component\CssSelector\Node as CssNode; /**  * A class for matching nodes against selector tokens. @@ -185,8 +189,8 @@      */     public static function containsWord(string $word, string $sentence): bool     { -         return in_array($word, preg_split('/\s+/', $sentence)); -     } +         return in_array($word, preg_split('/\s+/', $sentence) ?: []); +     }     /**      * Match the supplied CSS token against the supplied Element node and return TRUE if it is matched. @@ -194,40 +198,43 @@      * The $effectiveRoot specifies an Element node part of the hierarchy that is to be considered as root of the tree.      * Immediate child nodes will be treated as if they don't have a parent.      * -      * @param Css\NodeInterface $token -      * @param Dom\Element $node -      * @param Dom\Element|null $effectiveRoot +      * @param CssNode\NodeInterface $token +      * @param DomNode\Element $node +      * @param DomNode\Element|null $effectiveRoot      * @return bool      */ -     public function match(Css\NodeInterface $token, Dom\Element $node, Dom\Element $effectiveRoot = null): bool -     { -         switch (true) { -             case $token instanceof Css\SelectorNode: -                 return $this->match($token->getTree(), $node, $effectiveRoot); - -             case $token instanceof Css\ElementNode: -                 return $this->matchElementNode($token, $node); +     public function match( +         CssNode\NodeInterface $token, +         DomNode\Element $node, +         DomNode\Element $effectiveRoot = null +     ): bool { +         switch (true) { +             case $token instanceof CssNode\SelectorNode: +                 return $this->match($token->getTree(), $node, $effectiveRoot); -             case $token instanceof Css\AttributeNode: -                 return $this->matchAttributeNode($token, $node, $effectiveRoot); +             case $token instanceof CssNode\ElementNode: +                 return $this->matchElementNode($token, $node); -             case $token instanceof Css\ClassNode: -                 return $this->matchClassNode($token, $node, $effectiveRoot); +             case $token instanceof CssNode\AttributeNode: +                 return $this->matchAttributeNode($token, $node, $effectiveRoot); -             case $token instanceof Css\HashNode: -                 return $this->matchHashNode($token, $node, $effectiveRoot); +             case $token instanceof CssNode\ClassNode: +                 return $this->matchClassNode($token, $node, $effectiveRoot); -             case $token instanceof Css\CombinedSelectorNode: -                 return $this->matchCombinedSelectorNode($token, $node, $effectiveRoot); +             case $token instanceof CssNode\HashNode: +                 return $this->matchHashNode($token, $node, $effectiveRoot); -             default: -                 throw new \RuntimeException(sprintf( -                     'Selector token %s is not supported yet.', -                     get_class($token) -                 )); -         } -     } - } +             case $token instanceof CssNode\CombinedSelectorNode: +                 return $this->matchCombinedSelectorNode($token, $node, $effectiveRoot); + +             default: +                 throw new \RuntimeException(sprintf( +                     'Selector token %s is not supported yet.', +                     get_class($token) +                 )); +         } +     } + } @@ -240,7 +247,7 @@

Legend

Dead Code

- Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:08:03 EEST 2018. + Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:43:17 EEST 2018.

diff --git a/docs/coverage/SelectorMatcher/AttributeNodeTrait.php.html b/docs/coverage/SelectorMatcher/AttributeNodeTrait.php.html index d4f1537..3652127 100644 --- a/docs/coverage/SelectorMatcher/AttributeNodeTrait.php.html +++ b/docs/coverage/SelectorMatcher/AttributeNodeTrait.php.html @@ -141,9 +141,9 @@ namespace SDom\SelectorMatcher; use SDom\Node\Element; - use SDom\Node\NodeInterface; - use SDom\SelectorMatcher; - use Symfony\Component\CssSelector\Node\AttributeNode; + use SDom\SelectorMatcher; + use Symfony\Component\CssSelector\Node\AttributeNode; + use Symfony\Component\CssSelector\Node\NodeInterface; /**  * @pattern E[foo] @@ -274,7 +274,7 @@

Legend

Dead Code

- Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:08:03 EEST 2018. + Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:43:17 EEST 2018.

diff --git a/docs/coverage/SelectorMatcher/ClassNodeTrait.php.html b/docs/coverage/SelectorMatcher/ClassNodeTrait.php.html index f8820f4..f09c362 100644 --- a/docs/coverage/SelectorMatcher/ClassNodeTrait.php.html +++ b/docs/coverage/SelectorMatcher/ClassNodeTrait.php.html @@ -141,9 +141,9 @@ namespace SDom\SelectorMatcher; use SDom\Node\Element; - use SDom\Node\NodeInterface; - use SDom\SelectorMatcher; - use Symfony\Component\CssSelector\Node\ClassNode; + use SDom\SelectorMatcher; + use Symfony\Component\CssSelector\Node\ClassNode; + use Symfony\Component\CssSelector\Node\NodeInterface; /**  * @pattern E.warning @@ -196,7 +196,7 @@

Legend

Dead Code

- Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:08:03 EEST 2018. + Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:43:17 EEST 2018.

diff --git a/docs/coverage/SelectorMatcher/CombinedSelectorNodeTrait.php.html b/docs/coverage/SelectorMatcher/CombinedSelectorNodeTrait.php.html index 763c8f5..7212831 100644 --- a/docs/coverage/SelectorMatcher/CombinedSelectorNodeTrait.php.html +++ b/docs/coverage/SelectorMatcher/CombinedSelectorNodeTrait.php.html @@ -245,8 +245,8 @@ namespace SDom\SelectorMatcher; use SDom\Node\Element; - use SDom\Node\NodeInterface; - use Symfony\Component\CssSelector\Node\CombinedSelectorNode; + use Symfony\Component\CssSelector\Node\CombinedSelectorNode; + use Symfony\Component\CssSelector\Node\NodeInterface; /**  * @pattern E F @@ -475,7 +475,7 @@

Legend

Dead Code

- Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:08:03 EEST 2018. + Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:43:17 EEST 2018.

diff --git a/docs/coverage/SelectorMatcher/ElementNodeTrait.php.html b/docs/coverage/SelectorMatcher/ElementNodeTrait.php.html index 66fcefc..a05ce61 100644 --- a/docs/coverage/SelectorMatcher/ElementNodeTrait.php.html +++ b/docs/coverage/SelectorMatcher/ElementNodeTrait.php.html @@ -141,8 +141,8 @@ namespace SDom\SelectorMatcher; use SDom\Node\Element; - use SDom\Node\NodeInterface; - use Symfony\Component\CssSelector\Node\ElementNode; + use Symfony\Component\CssSelector\Node\ElementNode; + use Symfony\Component\CssSelector\Node\NodeInterface; /**  * @pattern * @@ -194,7 +194,7 @@

Legend

Dead Code

- Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:08:03 EEST 2018. + Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:43:17 EEST 2018.

diff --git a/docs/coverage/SelectorMatcher/HashNodeTrait.php.html b/docs/coverage/SelectorMatcher/HashNodeTrait.php.html index 734ddf9..aa75531 100644 --- a/docs/coverage/SelectorMatcher/HashNodeTrait.php.html +++ b/docs/coverage/SelectorMatcher/HashNodeTrait.php.html @@ -141,8 +141,8 @@ namespace SDom\SelectorMatcher; use SDom\Node\Element; - use SDom\Node\NodeInterface; - use Symfony\Component\CssSelector\Node\HashNode; + use Symfony\Component\CssSelector\Node\HashNode; + use Symfony\Component\CssSelector\Node\NodeInterface; /**  * @pattern E#myid @@ -195,7 +195,7 @@

Legend

Dead Code

- Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:08:03 EEST 2018. + Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:43:17 EEST 2018.

diff --git a/docs/coverage/SelectorMatcher/dashboard.html b/docs/coverage/SelectorMatcher/dashboard.html index 8a3481a..1abc79b 100644 --- a/docs/coverage/SelectorMatcher/dashboard.html +++ b/docs/coverage/SelectorMatcher/dashboard.html @@ -137,7 +137,7 @@

Project Risks

diff --git a/docs/coverage/SelectorMatcher/index.html b/docs/coverage/SelectorMatcher/index.html index fc84744..9484ec3 100644 --- a/docs/coverage/SelectorMatcher/index.html +++ b/docs/coverage/SelectorMatcher/index.html @@ -221,7 +221,7 @@

Legend

High: 90% to 100%

- Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:08:03 EEST 2018. + Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:43:17 EEST 2018.

diff --git a/docs/coverage/dashboard.html b/docs/coverage/dashboard.html index b3558a0..e6b8119 100644 --- a/docs/coverage/dashboard.html +++ b/docs/coverage/dashboard.html @@ -75,7 +75,7 @@

Project Risks

- SDom\Dom503 + SDom\Dom498 @@ -113,15 +113,15 @@

Insufficient Coverage

- __toString0% - before0% - after0% - attr0% - removeAttr0% - text0% - html0% - append85% - prepend85% + __toString0% + before0% + after0% + attr0% + removeAttr0% + text0% + html0% + append85% + prepend85% @@ -138,15 +138,15 @@

Project Risks

- html72 - text72 - before42 - after42 - attr42 - removeAttr12 - __toString6 - append5 - prepend5 + html72 + text72 + before42 + after42 + attr42 + removeAttr12 + __toString6 + append5 + prepend5 @@ -156,7 +156,7 @@

Project Risks

@@ -245,7 +245,7 @@

Project Risks

chart.yAxis.axisLabel('Cyclomatic Complexity'); d3.select('#classComplexity svg') - .datum(getComplexityData([[73.38709677419355,139,"SDom\\Dom<\/a>"],[100,13,"SDom\\Node\\CData<\/a>"],[100,13,"SDom\\Node\\Comment<\/a>"],[100,8,"SDom\\Node\\DocType<\/a>"],[100,47,"SDom\\Node\\Element<\/a>"],[100,13,"SDom\\Node\\Text<\/a>"],[100,8,"SDom\\SelectorMatcher<\/a>"],[100,17,"AttributeNodeTrait<\/a>"],[100,4,"ClassNodeTrait<\/a>"],[100,28,"CombinedSelectorNodeTrait<\/a>"],[100,3,"ElementNodeTrait<\/a>"],[100,4,"HashNodeTrait<\/a>"]], 'Class Complexity')) + .datum(getComplexityData([[73.49397590361446,139,"SDom\\Dom<\/a>"],[100,13,"SDom\\Node\\CData<\/a>"],[100,13,"SDom\\Node\\Comment<\/a>"],[100,8,"SDom\\Node\\DocType<\/a>"],[100,47,"SDom\\Node\\Element<\/a>"],[100,13,"SDom\\Node\\Text<\/a>"],[100,9,"SDom\\SelectorMatcher<\/a>"],[100,17,"AttributeNodeTrait<\/a>"],[100,4,"ClassNodeTrait<\/a>"],[100,28,"CombinedSelectorNodeTrait<\/a>"],[100,3,"ElementNodeTrait<\/a>"],[100,4,"HashNodeTrait<\/a>"]], 'Class Complexity')) .transition() .duration(500) .call(chart); @@ -269,7 +269,7 @@

Project Risks

chart.yAxis.axisLabel('Method Complexity'); d3.select('#methodComplexity svg') - .datum(getComplexityData([[100,5,"
SDom\\Dom::createInvalidContentException<\/a>"],[100,5,"SDom\\Dom::traverseMatch<\/a>"],[100,4,"SDom\\Dom::findFirstElement<\/a>"],[100,5,"SDom\\Dom::findFirstInnermostElement<\/a>"],[100,18,"SDom\\Dom::__construct<\/a>"],[0,2,"SDom\\Dom::__toString<\/a>"],[100,1,"SDom\\Dom::getIterator<\/a>"],[100,1,"SDom\\Dom::anonymousFunction:292#1280<\/a>"],[100,1,"SDom\\Dom::count<\/a>"],[100,5,"SDom\\Dom::get<\/a>"],[100,3,"SDom\\Dom::add<\/a>"],[100,1,"SDom\\Dom::clear<\/a>"],[100,2,"SDom\\Dom::eq<\/a>"],[100,1,"SDom\\Dom::first<\/a>"],[100,1,"SDom\\Dom::last<\/a>"],[100,4,"SDom\\Dom::children<\/a>"],[85.71428571428571,5,"SDom\\Dom::append<\/a>"],[85.71428571428571,5,"SDom\\Dom::prepend<\/a>"],[0,6,"SDom\\Dom::before<\/a>"],[0,6,"SDom\\Dom::after<\/a>"],[100,7,"SDom\\Dom::wrap<\/a>"],[100,2,"SDom\\Dom::wrapInner<\/a>"],[100,5,"SDom\\Dom::find<\/a>"],[100,6,"SDom\\Dom::addClass<\/a>"],[100,8,"SDom\\Dom::removeClass<\/a>"],[100,5,"SDom\\Dom::hasClass<\/a>"],[0,6,"SDom\\Dom::attr<\/a>"],[0,3,"SDom\\Dom::removeAttr<\/a>"],[0,8,"SDom\\Dom::text<\/a>"],[0,8,"SDom\\Dom::html<\/a>"],[100,1,"SDom\\Node\\CData::__construct<\/a>"],[100,1,"SDom\\Node\\CData::__toString<\/a>"],[100,1,"SDom\\Node\\CData::__clone<\/a>"],[100,2,"SDom\\Node\\CData::parent<\/a>"],[100,4,"SDom\\Node\\CData::attach<\/a>"],[100,3,"SDom\\Node\\CData::detach<\/a>"],[100,1,"SDom\\Node\\CData::clone<\/a>"],[100,1,"SDom\\Node\\Comment::__construct<\/a>"],[100,1,"SDom\\Node\\Comment::__toString<\/a>"],[100,1,"SDom\\Node\\Comment::__clone<\/a>"],[100,2,"SDom\\Node\\Comment::parent<\/a>"],[100,4,"SDom\\Node\\Comment::attach<\/a>"],[100,3,"SDom\\Node\\Comment::detach<\/a>"],[100,1,"SDom\\Node\\Comment::clone<\/a>"],[100,1,"SDom\\Node\\DocType::__construct<\/a>"],[100,1,"SDom\\Node\\DocType::__toString<\/a>"],[100,1,"SDom\\Node\\DocType::__clone<\/a>"],[100,2,"SDom\\Node\\DocType::parent<\/a>"],[100,1,"SDom\\Node\\DocType::attach<\/a>"],[100,1,"SDom\\Node\\DocType::detach<\/a>"],[100,1,"SDom\\Node\\DocType::clone<\/a>"],[100,1,"SDom\\Node\\Element::__construct<\/a>"],[100,5,"SDom\\Node\\Element::__toString<\/a>"],[100,1,"SDom\\Node\\Element::__clone<\/a>"],[100,1,"SDom\\Node\\Element::getTag<\/a>"],[100,1,"SDom\\Node\\Element::hasAttribute<\/a>"],[100,1,"SDom\\Node\\Element::setAttribute<\/a>"],[100,3,"SDom\\Node\\Element::getAttribute<\/a>"],[100,2,"SDom\\Node\\Element::removeAttribute<\/a>"],[100,2,"SDom\\Node\\Element::parent<\/a>"],[100,4,"SDom\\Node\\Element::attach<\/a>"],[100,3,"SDom\\Node\\Element::detach<\/a>"],[100,3,"SDom\\Node\\Element::clone<\/a>"],[100,1,"SDom\\Node\\Element::getIterator<\/a>"],[100,1,"SDom\\Node\\Element::count<\/a>"],[100,3,"SDom\\Node\\Element::insertAfter<\/a>"],[100,3,"SDom\\Node\\Element::insertBefore<\/a>"],[100,1,"SDom\\Node\\Element::isChild<\/a>"],[100,4,"SDom\\Node\\Element::get<\/a>"],[100,2,"SDom\\Node\\Element::index<\/a>"],[100,2,"SDom\\Node\\Element::removeChild<\/a>"],[100,2,"SDom\\Node\\Element::clear<\/a>"],[100,1,"SDom\\Node\\Element::isVoid<\/a>"],[100,1,"SDom\\Node\\Text::__construct<\/a>"],[100,1,"SDom\\Node\\Text::__toString<\/a>"],[100,1,"SDom\\Node\\Text::__clone<\/a>"],[100,2,"SDom\\Node\\Text::parent<\/a>"],[100,4,"SDom\\Node\\Text::attach<\/a>"],[100,3,"SDom\\Node\\Text::detach<\/a>"],[100,1,"SDom\\Node\\Text::clone<\/a>"],[100,1,"SDom\\SelectorMatcher::containsWord<\/a>"],[100,7,"SDom\\SelectorMatcher::match<\/a>"],[100,16,"AttributeNodeTrait::matchAttributeNode<\/a>"],[100,1,"AttributeNodeTrait::match<\/a>"],[100,3,"ClassNodeTrait::matchClassNode<\/a>"],[100,1,"ClassNodeTrait::match<\/a>"],[100,7,"CombinedSelectorNodeTrait::matchDescendantCombinedSelectorNode<\/a>"],[100,4,"CombinedSelectorNodeTrait::matchChildCombinedSelectorNode<\/a>"],[100,4,"CombinedSelectorNodeTrait::matchAdjacentCombinedSelectorNode<\/a>"],[100,6,"CombinedSelectorNodeTrait::matchGeneralSiblingCombinedSelectorNode<\/a>"],[100,6,"CombinedSelectorNodeTrait::matchCombinedSelectorNode<\/a>"],[100,1,"CombinedSelectorNodeTrait::match<\/a>"],[100,2,"ElementNodeTrait::matchElementNode<\/a>"],[100,1,"ElementNodeTrait::match<\/a>"],[100,3,"HashNodeTrait::matchHashNode<\/a>"],[100,1,"HashNodeTrait::match<\/a>"]], 'Method Complexity')) + .datum(getComplexityData([[100,5,"SDom\\Dom::createInvalidContentException<\/a>"],[100,5,"SDom\\Dom::traverseMatch<\/a>"],[100,4,"SDom\\Dom::findFirstElement<\/a>"],[100,5,"SDom\\Dom::findFirstInnermostElement<\/a>"],[100,18,"SDom\\Dom::__construct<\/a>"],[0,2,"SDom\\Dom::__toString<\/a>"],[100,1,"SDom\\Dom::getIterator<\/a>"],[100,1,"SDom\\Dom::anonymousFunction:294#1289<\/a>"],[100,1,"SDom\\Dom::count<\/a>"],[100,5,"SDom\\Dom::get<\/a>"],[100,3,"SDom\\Dom::add<\/a>"],[100,1,"SDom\\Dom::clear<\/a>"],[100,2,"SDom\\Dom::eq<\/a>"],[100,1,"SDom\\Dom::first<\/a>"],[100,1,"SDom\\Dom::last<\/a>"],[100,4,"SDom\\Dom::children<\/a>"],[85.71428571428571,5,"SDom\\Dom::append<\/a>"],[85.71428571428571,5,"SDom\\Dom::prepend<\/a>"],[0,6,"SDom\\Dom::before<\/a>"],[0,6,"SDom\\Dom::after<\/a>"],[100,7,"SDom\\Dom::wrap<\/a>"],[100,2,"SDom\\Dom::wrapInner<\/a>"],[100,5,"SDom\\Dom::find<\/a>"],[100,6,"SDom\\Dom::addClass<\/a>"],[100,8,"SDom\\Dom::removeClass<\/a>"],[100,5,"SDom\\Dom::hasClass<\/a>"],[0,6,"SDom\\Dom::attr<\/a>"],[0,3,"SDom\\Dom::removeAttr<\/a>"],[0,8,"SDom\\Dom::text<\/a>"],[0,8,"SDom\\Dom::html<\/a>"],[100,1,"SDom\\Node\\CData::__construct<\/a>"],[100,1,"SDom\\Node\\CData::__toString<\/a>"],[100,1,"SDom\\Node\\CData::__clone<\/a>"],[100,2,"SDom\\Node\\CData::parent<\/a>"],[100,4,"SDom\\Node\\CData::attach<\/a>"],[100,3,"SDom\\Node\\CData::detach<\/a>"],[100,1,"SDom\\Node\\CData::clone<\/a>"],[100,1,"SDom\\Node\\Comment::__construct<\/a>"],[100,1,"SDom\\Node\\Comment::__toString<\/a>"],[100,1,"SDom\\Node\\Comment::__clone<\/a>"],[100,2,"SDom\\Node\\Comment::parent<\/a>"],[100,4,"SDom\\Node\\Comment::attach<\/a>"],[100,3,"SDom\\Node\\Comment::detach<\/a>"],[100,1,"SDom\\Node\\Comment::clone<\/a>"],[100,1,"SDom\\Node\\DocType::__construct<\/a>"],[100,1,"SDom\\Node\\DocType::__toString<\/a>"],[100,1,"SDom\\Node\\DocType::__clone<\/a>"],[100,2,"SDom\\Node\\DocType::parent<\/a>"],[100,1,"SDom\\Node\\DocType::attach<\/a>"],[100,1,"SDom\\Node\\DocType::detach<\/a>"],[100,1,"SDom\\Node\\DocType::clone<\/a>"],[100,1,"SDom\\Node\\Element::__construct<\/a>"],[100,5,"SDom\\Node\\Element::__toString<\/a>"],[100,1,"SDom\\Node\\Element::__clone<\/a>"],[100,1,"SDom\\Node\\Element::getTag<\/a>"],[100,1,"SDom\\Node\\Element::hasAttribute<\/a>"],[100,1,"SDom\\Node\\Element::setAttribute<\/a>"],[100,3,"SDom\\Node\\Element::getAttribute<\/a>"],[100,2,"SDom\\Node\\Element::removeAttribute<\/a>"],[100,2,"SDom\\Node\\Element::parent<\/a>"],[100,4,"SDom\\Node\\Element::attach<\/a>"],[100,3,"SDom\\Node\\Element::detach<\/a>"],[100,3,"SDom\\Node\\Element::clone<\/a>"],[100,1,"SDom\\Node\\Element::getIterator<\/a>"],[100,1,"SDom\\Node\\Element::count<\/a>"],[100,3,"SDom\\Node\\Element::insertAfter<\/a>"],[100,3,"SDom\\Node\\Element::insertBefore<\/a>"],[100,1,"SDom\\Node\\Element::isChild<\/a>"],[100,4,"SDom\\Node\\Element::get<\/a>"],[100,2,"SDom\\Node\\Element::index<\/a>"],[100,2,"SDom\\Node\\Element::removeChild<\/a>"],[100,2,"SDom\\Node\\Element::clear<\/a>"],[100,1,"SDom\\Node\\Element::isVoid<\/a>"],[100,1,"SDom\\Node\\Text::__construct<\/a>"],[100,1,"SDom\\Node\\Text::__toString<\/a>"],[100,1,"SDom\\Node\\Text::__clone<\/a>"],[100,2,"SDom\\Node\\Text::parent<\/a>"],[100,4,"SDom\\Node\\Text::attach<\/a>"],[100,3,"SDom\\Node\\Text::detach<\/a>"],[100,1,"SDom\\Node\\Text::clone<\/a>"],[100,2,"SDom\\SelectorMatcher::containsWord<\/a>"],[100,7,"SDom\\SelectorMatcher::match<\/a>"],[100,16,"AttributeNodeTrait::matchAttributeNode<\/a>"],[100,1,"AttributeNodeTrait::match<\/a>"],[100,3,"ClassNodeTrait::matchClassNode<\/a>"],[100,1,"ClassNodeTrait::match<\/a>"],[100,7,"CombinedSelectorNodeTrait::matchDescendantCombinedSelectorNode<\/a>"],[100,4,"CombinedSelectorNodeTrait::matchChildCombinedSelectorNode<\/a>"],[100,4,"CombinedSelectorNodeTrait::matchAdjacentCombinedSelectorNode<\/a>"],[100,6,"CombinedSelectorNodeTrait::matchGeneralSiblingCombinedSelectorNode<\/a>"],[100,6,"CombinedSelectorNodeTrait::matchCombinedSelectorNode<\/a>"],[100,1,"CombinedSelectorNodeTrait::match<\/a>"],[100,2,"ElementNodeTrait::matchElementNode<\/a>"],[100,1,"ElementNodeTrait::match<\/a>"],[100,3,"HashNodeTrait::matchHashNode<\/a>"],[100,1,"HashNodeTrait::match<\/a>"]], 'Method Complexity')) .transition() .duration(500) .call(chart); diff --git a/docs/coverage/index.html b/docs/coverage/index.html index 18d0507..9d5828b 100644 --- a/docs/coverage/index.html +++ b/docs/coverage/index.html @@ -43,13 +43,13 @@ Total
-
- 88.00% covered (warning) +
+ 87.91% covered (warning)
-
88.00%
-
484 / 550
+
87.91%
+
480 / 546
90.00% covered (success) @@ -77,7 +77,7 @@
100.00%
-
182 / 182
+
183 / 183
100.00% covered (success) @@ -127,13 +127,13 @@ Dom.php
-
- 73.39% covered (warning) +
+ 73.49% covered (warning)
-
73.39%
-
182 / 248
+
73.49%
+
183 / 249
68.97% covered (warning) @@ -161,7 +161,7 @@
100.00%
-
16 / 16
+
10 / 10
100.00% covered (success) @@ -192,7 +192,7 @@

Legend

High: 90% to 100%

- Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:08:03 EEST 2018. + Generated by php-code-coverage 5.3.0-1-g982ce79 using PHP 7.2.2 with Xdebug 2.6.0 and PHPUnit 6.5.5 at Sun Apr 1 22:43:17 EEST 2018.

diff --git a/docs/docs/class-SDom.Dom.html b/docs/docs/class-SDom.Dom.html index a8816ec..a9d8a98 100644 --- a/docs/docs/class-SDom.Dom.html +++ b/docs/docs/class-SDom.Dom.html @@ -282,7 +282,7 @@

Dom

# - __construct( mixed $content = NULL ) + __construct( mixed $content = NULL )
Dom constructor. @@ -325,7 +325,7 @@

Dom

# - __toString( ) + __toString( )
Return the concatenated string representation of all nodes in the collection. @@ -357,7 +357,7 @@

Dom

# - getIterator( ) + getIterator( )
Return an \ArrayIterator with all nodes wrapped in a Dom instance. @@ -397,7 +397,7 @@

Implementation of

# - count( ) + count( )
Return the number of wrapped nodes. @@ -437,7 +437,7 @@

Implementation of

# - get( int $index = NULL ) + get( int $index = NULL )
Retrieve a NodeInterface instance for the specified index, or an array of all NodeInterface instances if index @@ -472,7 +472,7 @@

Implementation of

# - add( $content ) + add( $content )
Add the specified content to the end of the collection. @@ -504,7 +504,7 @@

Implementation of

# - clear( ) + clear( )
Clear the collection. @@ -536,7 +536,7 @@

Implementation of

# - eq( int $index ) + eq( int $index )
Retrieve a new Dom collection where the set of matched elements is reduced to the one at the specified index. @@ -570,7 +570,7 @@

Implementation of

# - first( ) + first( )
Retrieve a new Dom collection where the set of matched elements is reduced to the first in the set. @@ -604,7 +604,7 @@

Implementation of

# - last( ) + last( )
Retrieve a new Dom collection where the set of matched elements is reduced to the last in the set. @@ -638,7 +638,7 @@

Implementation of

# - children( ) + children( )
Get a new Dom collection with the immediate child nodes of each of the Element nodes in the collection. @@ -670,7 +670,7 @@

Implementation of

# - append( $content ) + append( $content )
Insert content after all immediate child nodes of each Element node in the collection. @@ -710,7 +710,7 @@

Implementation of

# - prepend( $content ) + prepend( $content )
Insert content before all immediate child nodes of each Element node in the collection. @@ -752,7 +752,7 @@

Implementation of

# - before( $content ) + before( $content )
Insert content before each Element node in the collection. If an element in the collection does not have a @@ -794,7 +794,7 @@

Implementation of

# - after( $content ) + after( $content )
Insert content after each Element node in the collection. If an element in the collection does not have a @@ -836,7 +836,7 @@

Implementation of

# - wrap( $content ) + wrap( $content )
Wrap a clone of the supplied content around each node with a parent (not only element nodes) in the collection. @@ -880,7 +880,7 @@

Implementation of

# - wrapInner( $content ) + wrapInner( $content )
Wrap a clone of the supplied content around each child node (not only element nodes) of nodes in the collection. @@ -916,7 +916,7 @@

Implementation of

# - find( string $selector ) + find( string $selector )
Return a new Dom collection of all the descendants of each Element node in the current collection, @@ -949,7 +949,7 @@

Implementation of

# - addClass( string $className ) + addClass( string $className )
Adds the specified class(es) to each Element node in the collection. @@ -981,7 +981,7 @@

Implementation of

# - removeClass( string $className = NULL ) + removeClass( string $className = NULL )
Remove a single class, multiple classes, or all classes from each Element node in the collection. @@ -1013,7 +1013,7 @@

Implementation of

# - hasClass( string $className ) + hasClass( string $className )
Return TRUE if at least one of the Element nodes in the collection has the specified class assigned. @@ -1045,7 +1045,7 @@

Implementation of

# - attr( string $name , string $value = NULL ) + attr( string $name , string $value = NULL )
Get the value of an attribute for the first Element node in the collection. @@ -1079,7 +1079,7 @@

Implementation of

# - removeAttr( string $name ) + removeAttr( string $name )
Remove an attribute from each Element node in the collection. @@ -1111,7 +1111,7 @@

Implementation of

# - text( string $text = NULL ) + text( string $text = NULL )
Get the combined text contents of each Element node in the collection, including their descendants. @@ -1145,7 +1145,7 @@

Implementation of

# - html( string $html = NULL ) + html( string $html = NULL )
Get the HTML contents of the first Element node in the collection. diff --git a/docs/docs/class-SDom.Node.Element.html b/docs/docs/class-SDom.Node.Element.html index 3be24bb..7ebfcbb 100644 --- a/docs/docs/class-SDom.Node.Element.html +++ b/docs/docs/class-SDom.Node.Element.html @@ -739,7 +739,7 @@

Implementation of

# - insertBefore( SDom\Node\NodeInterface $node , SDom\Node\NodeInterface $before = NULL ) + insertBefore( SDom\Node\NodeInterface $node , SDom\Node\NodeInterface $before = NULL )
Insert content at the beginning of the list of child nodes, or before the specified target node. @@ -774,7 +774,7 @@

Implementation of

# - isChild( SDom\Node\NodeInterface $node ) + isChild( SDom\Node\NodeInterface $node )
Returns TRUE if the specified node is an immediate child of the current node. @@ -806,7 +806,7 @@

Implementation of

# - get( int $index ) + get( int $index )
Retrieve a NodeInterface instance (immediate child node) for the specified index. @@ -840,7 +840,7 @@

Implementation of

# - index( SDom\Node\NodeInterface $node ) + index( SDom\Node\NodeInterface $node )
Retrieve the positional index of the specified NodeInterface in the list of immediate child nodes. @@ -874,7 +874,7 @@

Implementation of

# - removeChild( SDom\Node\NodeInterface $node ) + removeChild( SDom\Node\NodeInterface $node )
Remove the specified node from the list of immediate children of this node. @@ -909,7 +909,7 @@

Implementation of

# - clear( ) + clear( )
Remove all child nodes. @@ -941,7 +941,7 @@

Implementation of

# - isVoid( ) + isVoid( )
Returns TRUE if the element's tag matches the list of void element tags. diff --git a/docs/docs/class-SDom.SelectorMatcher.html b/docs/docs/class-SDom.SelectorMatcher.html index 66e613d..8419678 100644 --- a/docs/docs/class-SDom.SelectorMatcher.html +++ b/docs/docs/class-SDom.SelectorMatcher.html @@ -177,7 +177,7 @@

SelectorMatcher

# - match( Symfony\Component\CssSelector\Node\NodeInterface $token , SDom\Node\Element $node , SDom\Node\Element $effectiveRoot = NULL ) + match( Symfony\Component\CssSelector\Node\NodeInterface $token , SDom\Node\Element $node , SDom\Node\Element $effectiveRoot = NULL )
Match the supplied CSS token against the supplied Element node and return TRUE if it is matched. diff --git a/docs/docs/source-class-SDom.Dom.html b/docs/docs/source-class-SDom.Dom.html index ec6837a..977e4d8 100644 --- a/docs/docs/source-class-SDom.Dom.html +++ b/docs/docs/source-class-SDom.Dom.html @@ -68,7 +68,7 @@
-
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670: 671: 672: 673: 674: 675: 676: 677: 678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688: 689: 690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707: 708: 709: 710: 711: 712: 713: 714: 715: 716: 717: 718: 719: 720: 721: 722: 723: 724: 725: 726: 727: 728: 729: 730: 731: 732: 733: 734: 735: 736: 737: 738: 739: 740: 741: 742: 743: 744: 745: 746: 747: 748: 749: 750: 751: 752: 753: 754: 755: 756: 757: 758: 759: 760: 761: 762: 763: 764: 765: 766: 767: 768: 769: 770: 771: 772: 773: 774: 775: 776: 777: 778: 779: 780: 781: 782: 783: 784: 785: 786: 787: 788: 789: 790: 791: 792: 793: 794: 795: 796: 797: 798: 799: 800: 801: 802: 803: 804: 805: 806: 807: 808: 809: 810: 811: 812: 813: 814: 815: 816: 817: 818: 819: 820: 821: 822: 823: 824: 825: 826: 827: 828: 829: 830: 831: 832: 833: 834: 835: 836: 837: 838: 839: 840: 841: 842: 843: 844: 845: 846: 847: 848: 849: 850: 851: 852: 853: 854: 855: 856: 857: 858: 859: 860: 861: 862: 863: 864: 865: 866: 867: 868: 869: 870: 871: 872: 873: 874: 875: 876: 877: 878: 879: 880: 881: 882: 883: 884: 885: 886: 887: 888: 889: 890: 891: 892: 893: 894: 895: 896: 897: 898: 899: 900: 901: 902: 903: 904: 905: 906: 907: 908: 
+
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670: 671: 672: 673: 674: 675: 676: 677: 678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688: 689: 690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707: 708: 709: 710: 711: 712: 713: 714: 715: 716: 717: 718: 719: 720: 721: 722: 723: 724: 725: 726: 727: 728: 729: 730: 731: 732: 733: 734: 735: 736: 737: 738: 739: 740: 741: 742: 743: 744: 745: 746: 747: 748: 749: 750: 751: 752: 753: 754: 755: 756: 757: 758: 759: 760: 761: 762: 763: 764: 765: 766: 767: 768: 769: 770: 771: 772: 773: 774: 775: 776: 777: 778: 779: 780: 781: 782: 783: 784: 785: 786: 787: 788: 789: 790: 791: 792: 793: 794: 795: 796: 797: 798: 799: 800: 801: 802: 803: 804: 805: 806: 807: 808: 809: 810: 811: 812: 813: 814: 815: 816: 817: 818: 819: 820: 821: 822: 823: 824: 825: 826: 827: 828: 829: 830: 831: 832: 833: 834: 835: 836: 837: 838: 839: 840: 841: 842: 843: 844: 845: 846: 847: 848: 849: 850: 851: 852: 853: 854: 855: 856: 857: 858: 859: 860: 861: 862: 863: 864: 865: 866: 867: 868: 869: 870: 871: 872: 873: 874: 875: 876: 877: 878: 879: 880: 881: 882: 883: 884: 885: 886: 887: 888: 889: 890: 891: 892: 893: 894: 895: 896: 897: 898: 899: 900: 901: 902: 903: 904: 905: 906: 907: 908: 909: 910: 
<?php
 
 namespace SDom;
@@ -299,684 +299,686 @@
                  * @var Tokens\Token $child
                  */
                 foreach ($content->getChildren() as $child) {
-                    $node->insertAfter((new static($child))->get(0));
-                }
-
-                $this->nodes = [$node];
-                break;
-
-            case $content instanceof Tokens\TokenCollection:
-                $this->nodes = [];
-
-                /** @var Tokens\Token $token */
-                foreach ($content as $token) {
-                    $this->add($token);
-                }
-                break;
-
-            case is_string($content):
-                $this->nodes = [];
-
-                try {
-                    if (!isset(self::$tokenizer)) {
-                        self::$tokenizer = new HtmlTokenizer();
-                    }
-                    $tokenCollection = self::$tokenizer->parse($content);
-                } catch (\Exception $e) {
-                    throw static::createInvalidContentException($content);
-                }
-
-                /** @var Tokens\Token $token */
-                foreach ($tokenCollection as $token) {
-                    $this->add($token);
-                }
-                break;
-
-            default:
-                throw static::createInvalidContentException($content);
-        }
-    }
-
-    /**
-     * Return the concatenated string representation of all nodes in the collection.
-     *
-     * @return string
-     */
-    public function __toString(): string
-    {
-        $html = '';
-
-        foreach ($this->nodes as $node) {
-            $html .= (string) $node;
-        }
-
-        return $html;
-    }
-
-    /**
-     * Return an \ArrayIterator with all nodes wrapped in a Dom instance.
-     *
-     * @return \ArrayIterator
-     */
-    public function getIterator(): \ArrayIterator
-    {
-        return new \ArrayIterator(array_map(function (NodeInterface $node) {
-            return new static($node);
-        }, $this->nodes));
-    }
-
-    /**
-     * Return the number of wrapped nodes.
-     *
-     * @return int
-     */
-    public function count(): int
-    {
-        return count($this->nodes);
-    }
-
-    /**
-     * Retrieve a NodeInterface instance for the specified index, or an array of all NodeInterface instances if index
-     * is not specified.
-     *
-     * Throw \OutOfBoundsException exception if the specified index is out of bounds.
+                    /** @var NodeInterface $childNode */
+                    $childNode = (new static($child))->get(0);
+                    $node->insertAfter($childNode);
+                }
+
+                $this->nodes = [$node];
+                break;
+
+            case $content instanceof Tokens\TokenCollection:
+                $this->nodes = [];
+
+                /** @var Tokens\Token $token */
+                foreach ($content as $token) {
+                    $this->add($token);
+                }
+                break;
+
+            case is_string($content):
+                $this->nodes = [];
+
+                try {
+                    if (!isset(self::$tokenizer)) {
+                        self::$tokenizer = new HtmlTokenizer();
+                    }
+                    $tokenCollection = self::$tokenizer->parse($content);
+                } catch (\Exception $e) {
+                    throw static::createInvalidContentException($content);
+                }
+
+                /** @var Tokens\Token $token */
+                foreach ($tokenCollection as $token) {
+                    $this->add($token);
+                }
+                break;
+
+            default:
+                throw static::createInvalidContentException($content);
+        }
+    }
+
+    /**
+     * Return the concatenated string representation of all nodes in the collection.
+     *
+     * @return string
+     */
+    public function __toString(): string
+    {
+        $html = '';
+
+        foreach ($this->nodes as $node) {
+            $html .= (string) $node;
+        }
+
+        return $html;
+    }
+
+    /**
+     * Return an \ArrayIterator with all nodes wrapped in a Dom instance.
+     *
+     * @return \ArrayIterator
+     */
+    public function getIterator(): \ArrayIterator
+    {
+        return new \ArrayIterator(array_map(function (NodeInterface $node) {
+            return new static($node);
+        }, $this->nodes));
+    }
+
+    /**
+     * Return the number of wrapped nodes.
+     *
+     * @return int
+     */
+    public function count(): int
+    {
+        return count($this->nodes);
+    }
+
+    /**
+     * Retrieve a NodeInterface instance for the specified index, or an array of all NodeInterface instances if index
+     * is not specified.
      *
-     * @param int|null $index
-     * @return NodeInterface|NodeInterface[]
-     */
-    public function get(int $index = null)
-    {
-        if (!isset($index)) {
-            return $this->nodes;
-        }
-
-        $count = count($this);
+     * Throw \OutOfBoundsException exception if the specified index is out of bounds.
+     *
+     * @param int|null $index
+     * @return NodeInterface|NodeInterface[]
+     */
+    public function get(int $index = null)
+    {
+        if (!isset($index)) {
+            return $this->nodes;
+        }
 
-        if ($index < 0 || $index >= $count) {
-            throw new \OutOfBoundsException(sprintf(
-                'The requested node index %d is out of the collection bounds [%s].',
-                $index,
-                0 < $count ? '[0; ' . ($count - 1) . ']' : '(empty collection)'
-            ));
-        }
-
-        return $this->nodes[$index];
-    }
-
-    /**
-     * Add the specified content to the end of the collection.
-     *
-     * @param $content
-     * @return Dom
-     */
-    public function add($content): Dom
-    {
-        /** @var NodeInterface $node */
-        foreach ((new static($content))->nodes as $node) {
-            if (!in_array($node, $this->nodes, true)) {
-                $this->nodes[] = $node;
-            }
-        }
-
-        return $this;
-    }
-
-    /**
-     * Clear the collection.
-     *
-     * @return Dom
-     */
-    public function clear(): Dom
-    {
-        $this->nodes = [];
-        return $this;
-    }
-
-    /**
-     * Retrieve a new Dom collection where the set of matched elements is reduced to the one at the specified index.
-     * If the specified index is out of bounds an empty collection is returned.
-     *
-     * @param int $index
-     * @return Dom
-     */
-    public function eq(int $index): Dom
-    {
-        return array_key_exists($index, $this->nodes) ?
-            new static($this->nodes[$index]) :
-            new static();
-    }
-
-    /**
-     * Retrieve a new Dom collection where the set of matched elements is reduced to the first in the set.
-     * If the collection is empty a new empty collection is returned.
-     *
-     * @return Dom
-     */
-    public function first(): Dom
-    {
-        return $this->eq(0);
-    }
-
-    /**
-     * Retrieve a new Dom collection where the set of matched elements is reduced to the last in the set.
-     * If the collection is empty a new empty collection is returned.
-     *
-     * @return Dom
-     */
-    public function last(): Dom
-    {
-        return $this->eq(count($this) - 1);
-    }
-
-    /**
-     * Get a new Dom collection with the immediate child nodes of each of the Element nodes in the collection.
-     *
-     * @return Dom
-     */
-    public function children(): Dom
-    {
-        $dom = new Dom();
-
-        /** @var NodeInterface $node */
-        foreach ($this->nodes as $node) {
-            if (!$node instanceof Element) {
-                continue;
-            }
-
-            /** @var NodeInterface $child */
-            foreach ($node as $child) {
-                $dom->add($child);
-            }
-        }
-
-        return $dom;
-    }
-
-    /**
-     * Insert content after all immediate child nodes of each Element node in the collection.
-     *
-     * If any node derived from the content already has a parent node, a cloned copy will be used instead and it will
-     * be assigned a new parent node. This means that, if appended to more than one Element node, references to each
-     * appended node will only point to the very first insertion.
-     *
-     * E.g. if the same node is appended to two or more Element nodes, its reference will point to the node with the
-     * first Element as parent. Nodes appended to all other Element nodes will be cloned copies. The same rule applies
-     * to child nodes of appended nodes, at any depth, as the whole sub-tree is cloned recursively.
-     *
-     * @param $content
-     * @return Dom
-     */
-    public function append($content): Dom
-    {
-        $nodes = (new static($content))->nodes;
-
-        /** @var NodeInterface $node */
-        foreach ($this->nodes as $node) {
-            if (!$node instanceof Element) {
-                continue;
-            }
-
-            /** @var NodeInterface $child */
-            foreach ($nodes as $child) {
-                $node->insertAfter(null === $child->parent() ? $child : $child->clone());
-            }
-        }
-
-        return $this;
-    }
-
-    /**
-     * Insert content before all immediate child nodes of each Element node in the collection.
-     *
-     * If any node derived from the content already has a parent node, a cloned copy will be used instead and it will
-     * be assigned a new parent node. This means that, if prepended to more than one Element node, references to each
-     * prepended node will only point to the very first insertion.
-     *
-     * E.g. if the same node is prepended to two or more Element nodes, its reference will point to the node with the
-     * first Element as parent. Nodes prepended to all other Element nodes will be cloned copies. The same rule applies
-     * to child nodes of prepended nodes, at any depth, as the whole sub-tree is cloned recursively.
-     *
-     * If the supplied content resolves to a collection of nodes, they will be prepended as a group, keeping the order.
+        $count = count($this);
+
+        if ($index < 0 || $index >= $count) {
+            throw new \OutOfBoundsException(sprintf(
+                'The requested node index %d is out of the collection bounds [%s].',
+                $index,
+                0 < $count ? '[0; ' . ($count - 1) . ']' : '(empty collection)'
+            ));
+        }
+
+        return $this->nodes[$index];
+    }
+
+    /**
+     * Add the specified content to the end of the collection.
+     *
+     * @param $content
+     * @return Dom
+     */
+    public function add($content): Dom
+    {
+        /** @var NodeInterface $node */
+        foreach ((new static($content))->nodes as $node) {
+            if (!in_array($node, $this->nodes, true)) {
+                $this->nodes[] = $node;
+            }
+        }
+
+        return $this;
+    }
+
+    /**
+     * Clear the collection.
+     *
+     * @return Dom
+     */
+    public function clear(): Dom
+    {
+        $this->nodes = [];
+        return $this;
+    }
+
+    /**
+     * Retrieve a new Dom collection where the set of matched elements is reduced to the one at the specified index.
+     * If the specified index is out of bounds an empty collection is returned.
+     *
+     * @param int $index
+     * @return Dom
+     */
+    public function eq(int $index): Dom
+    {
+        return array_key_exists($index, $this->nodes) ?
+            new static($this->nodes[$index]) :
+            new static();
+    }
+
+    /**
+     * Retrieve a new Dom collection where the set of matched elements is reduced to the first in the set.
+     * If the collection is empty a new empty collection is returned.
+     *
+     * @return Dom
+     */
+    public function first(): Dom
+    {
+        return $this->eq(0);
+    }
+
+    /**
+     * Retrieve a new Dom collection where the set of matched elements is reduced to the last in the set.
+     * If the collection is empty a new empty collection is returned.
+     *
+     * @return Dom
+     */
+    public function last(): Dom
+    {
+        return $this->eq(count($this) - 1);
+    }
+
+    /**
+     * Get a new Dom collection with the immediate child nodes of each of the Element nodes in the collection.
+     *
+     * @return Dom
+     */
+    public function children(): Dom
+    {
+        $dom = new Dom();
+
+        /** @var NodeInterface $node */
+        foreach ($this->nodes as $node) {
+            if (!$node instanceof Element) {
+                continue;
+            }
+
+            /** @var NodeInterface $child */
+            foreach ($node as $child) {
+                $dom->add($child);
+            }
+        }
+
+        return $dom;
+    }
+
+    /**
+     * Insert content after all immediate child nodes of each Element node in the collection.
+     *
+     * If any node derived from the content already has a parent node, a cloned copy will be used instead and it will
+     * be assigned a new parent node. This means that, if appended to more than one Element node, references to each
+     * appended node will only point to the very first insertion.
+     *
+     * E.g. if the same node is appended to two or more Element nodes, its reference will point to the node with the
+     * first Element as parent. Nodes appended to all other Element nodes will be cloned copies. The same rule applies
+     * to child nodes of appended nodes, at any depth, as the whole sub-tree is cloned recursively.
+     *
+     * @param $content
+     * @return Dom
+     */
+    public function append($content): Dom
+    {
+        $nodes = (new static($content))->nodes;
+
+        /** @var NodeInterface $node */
+        foreach ($this->nodes as $node) {
+            if (!$node instanceof Element) {
+                continue;
+            }
+
+            /** @var NodeInterface $child */
+            foreach ($nodes as $child) {
+                $node->insertAfter(null === $child->parent() ? $child : $child->clone());
+            }
+        }
+
+        return $this;
+    }
+
+    /**
+     * Insert content before all immediate child nodes of each Element node in the collection.
+     *
+     * If any node derived from the content already has a parent node, a cloned copy will be used instead and it will
+     * be assigned a new parent node. This means that, if prepended to more than one Element node, references to each
+     * prepended node will only point to the very first insertion.
+     *
+     * E.g. if the same node is prepended to two or more Element nodes, its reference will point to the node with the
+     * first Element as parent. Nodes prepended to all other Element nodes will be cloned copies. The same rule applies
+     * to child nodes of prepended nodes, at any depth, as the whole sub-tree is cloned recursively.
      *
-     * @param $content
-     * @return Dom
-     */
-    public function prepend($content): Dom
-    {
-        $nodes = array_reverse((new static($content))->nodes);
-
-        /** @var NodeInterface $node */
-        foreach ($this->nodes as $node) {
-            if (!$node instanceof Element) {
-                continue;
-            }
-
-            /** @var NodeInterface $child */
-            foreach ($nodes as $child) {
-                $node->insertBefore(null === $child->parent() ? $child : $child->clone());
-            }
-        }
-
-        return $this;
-    }
-
-    /**
-     * Insert content before each Element node in the collection. If an element in the collection does not have a
-     * parent node it will be skipped / ignored.
-     *
-     * If any node derived from the content already has a parent node, a cloned copy will be used instead and it will
-     * be assigned a new parent node. This means that, if inserted before more than one Element node, references to
-     * each inserted node will only point to the very first successful insertion.
-     *
-     * E.g. if the same node is inserted before two or more Element nodes, its reference will point to the node
-     * inserted before the first eligible Element in the collection (an Element without a parent node is not eligible
-     * and will be ignored). Nodes inserted before all other Element nodes will be cloned copies. The same rule applies
-     * to child nodes of inserted nodes, at any depth, as the whole sub-tree is cloned recursively.
-     *
-     * @param $content
-     * @return Dom
-     */
-    public function before($content): Dom
-    {
-        /** @var NodeInterface $node */
-        foreach ($this->nodes as $node) {
-            if (!$node instanceof Element || null === $node->parent()) {
-                continue;
-            }
-
-            /** @var Element $parent */
-            $parent = $node->parent();
-
-            /** @var NodeInterface $child */
-            foreach (array_reverse((new static($content))->nodes) as $child) {
-                $parent->insertBefore(null === $child->parent() ? $child : $child->clone(), $node);
-            }
-        }
-
-        return $this;
-    }
-
-    /**
-     * Insert content after each Element node in the collection. If an element in the collection does not have a
-     * parent node it will be skipped / ignored.
-     *
-     * If any node derived from the content already has a parent node, a cloned copy will be used instead and it will
-     * be assigned a new parent node. This means that, if inserted after more than one Element node, references to
-     * each inserted node will only point to the very first successful insertion.
-     *
-     * E.g. if the same node is inserted after two or more Element nodes, its reference will point to the node
-     * inserted after the first eligible Element in the collection (an Element without a parent node is not eligible
-     * and will be ignored). Nodes inserted after all other Element nodes will be cloned copies. The same rule applies
-     * to child nodes of inserted nodes, at any depth, as the whole sub-tree is cloned recursively.
-     *
-     * @param $content
-     * @return Dom
-     */
-    public function after($content): Dom
-    {
-        /** @var NodeInterface $node */
-        foreach ($this->nodes as $node) {
-            if (!$node instanceof Element || null === $node->parent()) {
-                continue;
-            }
-
-            /** @var Element $parent */
-            $parent = $node->parent();
-
-            /** @var NodeInterface $child */
-            foreach (array_reverse((new static($content))->nodes) as $child) {
-                $parent->insertAfter(null === $child->parent() ? $child : $child->clone(), $node);
-            }
-        }
-
-        return $this;
-    }
-
-    /**
-     * Wrap a clone of the supplied content around each node with a parent (not only element nodes) in the collection.
-     *
-     * If the content resolves to a collection of more than one wrapping element node, use only the first one.
-     * If the wrapping element has children use a single-element-per-level sub-tree, where the wrapping element is
-     * the root and may contain one and only one element node, which may contain another one and only one element node
-     * and so on.
-     *
-     * Wrap the current collection nodes in clones of this sub-tree as immediate children of the inner-most element
-     * node of the tree. If a node in the collection does not have a parent element, ignore it.
-     *
-     * If the wrapping collection does not contain at least one element node, do nothing.
+     * If the supplied content resolves to a collection of nodes, they will be prepended as a group, keeping the order.
+     *
+     * @param $content
+     * @return Dom
+     */
+    public function prepend($content): Dom
+    {
+        $nodes = array_reverse((new static($content))->nodes);
+
+        /** @var NodeInterface $node */
+        foreach ($this->nodes as $node) {
+            if (!$node instanceof Element) {
+                continue;
+            }
+
+            /** @var NodeInterface $child */
+            foreach ($nodes as $child) {
+                $node->insertBefore(null === $child->parent() ? $child : $child->clone());
+            }
+        }
+
+        return $this;
+    }
+
+    /**
+     * Insert content before each Element node in the collection. If an element in the collection does not have a
+     * parent node it will be skipped / ignored.
+     *
+     * If any node derived from the content already has a parent node, a cloned copy will be used instead and it will
+     * be assigned a new parent node. This means that, if inserted before more than one Element node, references to
+     * each inserted node will only point to the very first successful insertion.
+     *
+     * E.g. if the same node is inserted before two or more Element nodes, its reference will point to the node
+     * inserted before the first eligible Element in the collection (an Element without a parent node is not eligible
+     * and will be ignored). Nodes inserted before all other Element nodes will be cloned copies. The same rule applies
+     * to child nodes of inserted nodes, at any depth, as the whole sub-tree is cloned recursively.
+     *
+     * @param $content
+     * @return Dom
+     */
+    public function before($content): Dom
+    {
+        /** @var NodeInterface $node */
+        foreach ($this->nodes as $node) {
+            if (!$node instanceof Element || null === $node->parent()) {
+                continue;
+            }
+
+            /** @var Element $parent */
+            $parent = $node->parent();
+
+            /** @var NodeInterface $child */
+            foreach (array_reverse((new static($content))->nodes) as $child) {
+                $parent->insertBefore(null === $child->parent() ? $child : $child->clone(), $node);
+            }
+        }
+
+        return $this;
+    }
+
+    /**
+     * Insert content after each Element node in the collection. If an element in the collection does not have a
+     * parent node it will be skipped / ignored.
+     *
+     * If any node derived from the content already has a parent node, a cloned copy will be used instead and it will
+     * be assigned a new parent node. This means that, if inserted after more than one Element node, references to
+     * each inserted node will only point to the very first successful insertion.
+     *
+     * E.g. if the same node is inserted after two or more Element nodes, its reference will point to the node
+     * inserted after the first eligible Element in the collection (an Element without a parent node is not eligible
+     * and will be ignored). Nodes inserted after all other Element nodes will be cloned copies. The same rule applies
+     * to child nodes of inserted nodes, at any depth, as the whole sub-tree is cloned recursively.
+     *
+     * @param $content
+     * @return Dom
+     */
+    public function after($content): Dom
+    {
+        /** @var NodeInterface $node */
+        foreach ($this->nodes as $node) {
+            if (!$node instanceof Element || null === $node->parent()) {
+                continue;
+            }
+
+            /** @var Element $parent */
+            $parent = $node->parent();
+
+            /** @var NodeInterface $child */
+            foreach (array_reverse((new static($content))->nodes) as $child) {
+                $parent->insertAfter(null === $child->parent() ? $child : $child->clone(), $node);
+            }
+        }
+
+        return $this;
+    }
+
+    /**
+     * Wrap a clone of the supplied content around each node with a parent (not only element nodes) in the collection.
+     *
+     * If the content resolves to a collection of more than one wrapping element node, use only the first one.
+     * If the wrapping element has children use a single-element-per-level sub-tree, where the wrapping element is
+     * the root and may contain one and only one element node, which may contain another one and only one element node
+     * and so on.
+     *
+     * Wrap the current collection nodes in clones of this sub-tree as immediate children of the inner-most element
+     * node of the tree. If a node in the collection does not have a parent element, ignore it.
      *
-     * Return the original collection for chaining.
+     * If the wrapping collection does not contain at least one element node, do nothing.
      *
-     * @param $content
-     * @return Dom
-     */
-    public function wrap($content): Dom
-    {
-        // get a detached clone of the first element node in the content
-        /** @var Element $wrapper */
-        $wrapper = static::findFirstElement((new static($content))->nodes);
-        if (!$wrapper) {
-            return $this;
-        }
-        $wrapper = $wrapper->clone()->detach();
-
-        // collapse the wrapper down to a single-element-per-level tree of clones
-        $inner = $wrapper;
-        while (0 < count($inner)) {
-            $element = static::findFirstElement($inner->getIterator()->getArrayCopy());
-            if (!$element) {
-                break;
-            }
-            $inner->clear()->insertAfter($inner = $element->clone());
-        }
-
-        // wrap nodes
-        foreach ($this->nodes as $node) {
-            if (null === $node->parent()) {
-                continue;
-            }
-
-            /** @var Element $insert */
-            $insert = $wrapper->clone();
-
-            /** @var Element $parent */
-            $parent = $node->parent();
-            $parent->insertAfter($insert, $node);
-
-            $inner = static::findFirstInnermostElement($insert->getIterator()->getArrayCopy());
+     * Return the original collection for chaining.
+     *
+     * @param $content
+     * @return Dom
+     */
+    public function wrap($content): Dom
+    {
+        // get a detached clone of the first element node in the content
+        /** @var Element $wrapper */
+        $wrapper = static::findFirstElement((new static($content))->nodes);
+        if (!$wrapper) {
+            return $this;
+        }
+        $wrapper = $wrapper->clone()->detach();
+
+        // collapse the wrapper down to a single-element-per-level tree of clones
+        $inner = $wrapper;
+        while (0 < count($inner)) {
+            $element = static::findFirstElement($inner->getIterator()->getArrayCopy());
+            if (!$element) {
+                break;
+            }
+            $inner->clear()->insertAfter($inner = $element->clone());
+        }
+
+        // wrap nodes
+        foreach ($this->nodes as $node) {
+            if (null === $node->parent()) {
+                continue;
+            }
+
+            /** @var Element $insert */
+            $insert = $wrapper->clone();
+
+            /** @var Element $parent */
+            $parent = $node->parent();
+            $parent->insertAfter($insert, $node);
 
-            if ($inner) {
-                $inner->insertAfter($node);
-            } else {
-                $insert->insertAfter($node);
-            }
-        }
-
-        return $this;
-    }
-
-    /**
-     * Wrap a clone of the supplied content around each child node (not only element nodes) of nodes in the collection.
-     *
-     * This function works exactly like wrap() except it wraps the children of the nodes in the collection instead.
+            $inner = static::findFirstInnermostElement($insert->getIterator()->getArrayCopy());
+
+            if ($inner) {
+                $inner->insertAfter($node);
+            } else {
+                $insert->insertAfter($node);
+            }
+        }
+
+        return $this;
+    }
+
+    /**
+     * Wrap a clone of the supplied content around each child node (not only element nodes) of nodes in the collection.
      *
-     * Return the original collection for chaining.
+     * This function works exactly like wrap() except it wraps the children of the nodes in the collection instead.
      *
-     * @param $content
-     * @return Dom
-     */
-    public function wrapInner($content): Dom
-    {
-        foreach ($this->children() as $child) {
-            $child->wrap($content);
-        }
-        return $this;
-    }
-
-    /**
-     * Return a new Dom collection of all the descendants of each Element node in the current collection,
-     * filtered by the specified CSS selector.
-     *
-     * @param string $selector
-     * @return Dom
-     */
-    public function find(string $selector): Dom
-    {
-        if (!isset(self::$selectorParser)) {
-            self::$selectorParser = new Parser();
-        }
-
-        if (!isset(self::$selectorMatcher)) {
-            self::$selectorMatcher = new SelectorMatcher();
-        }
-
-        $dom = new static();
-        $selectorTokens = self::$selectorParser->parse($selector);
-
-        foreach ($this->get() as $rootNode) {
-            /** @var NodeInterface $childNode */
-            foreach ($rootNode as $childNode) {
-                self::traverseMatch($dom, $selectorTokens, $childNode, $rootNode);
-            }
-        }
-
-        return $dom;
-    }
-
-    /**
-     * Adds the specified class(es) to each Element node in the collection.
-     *
-     * @param string $className
-     * @return Dom
-     */
-    public function addClass(string $className): Dom
-    {
-        $className = trim($className);
-
-        // bail if no classes to add
-        if ('' === $className) {
-            return $this;
-        }
-
-        $addClasses = preg_split('/\s+/', $className);
+     * Return the original collection for chaining.
+     *
+     * @param $content
+     * @return Dom
+     */
+    public function wrapInner($content): Dom
+    {
+        foreach ($this->children() as $child) {
+            $child->wrap($content);
+        }
+        return $this;
+    }
+
+    /**
+     * Return a new Dom collection of all the descendants of each Element node in the current collection,
+     * filtered by the specified CSS selector.
+     *
+     * @param string $selector
+     * @return Dom
+     */
+    public function find(string $selector): Dom
+    {
+        if (!isset(self::$selectorParser)) {
+            self::$selectorParser = new Parser();
+        }
+
+        if (!isset(self::$selectorMatcher)) {
+            self::$selectorMatcher = new SelectorMatcher();
+        }
+
+        $dom = new static();
+        $selectorTokens = self::$selectorParser->parse($selector);
+
+        foreach ($this->get() as $rootNode) {
+            /** @var NodeInterface $childNode */
+            foreach ($rootNode as $childNode) {
+                self::traverseMatch($dom, $selectorTokens, $childNode, $rootNode);
+            }
+        }
+
+        return $dom;
+    }
+
+    /**
+     * Adds the specified class(es) to each Element node in the collection.
+     *
+     * @param string $className
+     * @return Dom
+     */
+    public function addClass(string $className): Dom
+    {
+        $className = trim($className);
+
+        // bail if no classes to add
+        if ('' === $className) {
+            return $this;
+        }
 
-        /** @var NodeInterface $node */
-        foreach ($this->nodes as $node) {
-            if (!$node instanceof Element) {
-                continue;
-            }
-
-            // if the node already has a "class" attribute, merge all classes & make sure the result is unique
-            if ($node->hasAttribute('class')) {
-                $currentClassName = trim($node->getAttribute('class'));
-                $currentClasses = '' === $currentClassName ? [] : preg_split('/\s+/', $currentClassName);
-                $node->setAttribute('class', implode(' ', array_unique(array_merge($currentClasses, $addClasses))));
-            }
-
-            // if the node does not have a "class" attribute, directly set the new ones
-            else {
-                $node->setAttribute('class', implode(' ', $addClasses));
-            }
-        }
-
-        return $this;
-    }
-
-    /**
-     * Remove a single class, multiple classes, or all classes from each Element node in the collection.
-     *
-     * @param string|null $className
-     * @return Dom
-     */
-    public function removeClass(string $className = null): Dom
-    {
-        // if class to remove isn't set, remove all classes, but keep the "class" attribute present
-        if (!isset($className)) {
-            /** @var NodeInterface $node */
-            foreach ($this->nodes as $node) {
-                if (!$node instanceof Element || !$node->hasAttribute('class')) {
-                    continue;
-                }
-
-                $node->setAttribute('class', '');
-            }
-
-            return $this;
-        }
-
-        $removeClasses = preg_split('/\s+/', $className);
+        $addClasses = preg_split('/\s+/', $className);
+
+        /** @var NodeInterface $node */
+        foreach ($this->nodes as $node) {
+            if (!$node instanceof Element) {
+                continue;
+            }
+
+            // if the node already has a "class" attribute, merge all classes & make sure the result is unique
+            if ($node->hasAttribute('class')) {
+                $currentClassName = trim($node->getAttribute('class'));
+                $currentClasses = '' === $currentClassName ? [] : preg_split('/\s+/', $currentClassName);
+                $node->setAttribute('class', implode(' ', array_unique(array_merge($currentClasses, $addClasses))));
+            }
+
+            // if the node does not have a "class" attribute, directly set the new ones
+            else {
+                $node->setAttribute('class', implode(' ', $addClasses));
+            }
+        }
+
+        return $this;
+    }
+
+    /**
+     * Remove a single class, multiple classes, or all classes from each Element node in the collection.
+     *
+     * @param string|null $className
+     * @return Dom
+     */
+    public function removeClass(string $className = null): Dom
+    {
+        // if class to remove isn't set, remove all classes, but keep the "class" attribute present
+        if (!isset($className)) {
+            /** @var NodeInterface $node */
+            foreach ($this->nodes as $node) {
+                if (!$node instanceof Element || !$node->hasAttribute('class')) {
+                    continue;
+                }
+
+                $node->setAttribute('class', '');
+            }
+
+            return $this;
+        }
 
-        /** @var NodeInterface $node */
-        foreach ($this->nodes as $node) {
-            if (!$node instanceof Element || !$node->hasAttribute('class')) {
-                continue;
-            }
-
-            // set to the difference between the current classes and the remove ones
-            $currentClasses = preg_split('/\s+/', $node->getAttribute('class'));
-            $node->setAttribute('class', implode(' ', array_diff($currentClasses, $removeClasses)));
-        }
-
-        return $this;
-    }
-
-    /**
-     * Return TRUE if at least one of the Element nodes in the collection has the specified class assigned.
-     *
-     * @param string $className
-     * @return bool
-     */
-    public function hasClass(string $className): bool
-    {
-        /** @var NodeInterface $node */
-        foreach ($this->nodes as $node) {
-            if (!$node instanceof Element || !$node->hasAttribute('class')) {
-                continue;
-            }
-
-            if (SelectorMatcher::containsWord($className, $node->getAttribute('class'))) {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-    /**
-     * Get the value of an attribute for the first Element node in the collection.
-     * Set the value of an attribute for each Element node in the collection.
-     *
-     * @param string $name
-     * @param string|null $value
-     * @return string|null|$this
-     */
-    public function attr(string $name, string $value = null)
-    {
-        if (isset($value)) {
-            /** @var NodeInterface $node */
-            foreach ($this->nodes as $node) {
-                if (!$node instanceof Element) {
-                    continue;
-                }
-
-                $node->setAttribute($name, $value);
-            }
-
-            return $this;
-        }
-
-        /** @var NodeInterface $node */
-        foreach ($this->nodes as $node) {
-            if (!$node instanceof Element) {
-                continue;
-            }
-
-            return $node->getAttribute($name);
-        }
-
-        return null;
-    }
-
-    /**
-     * Remove an attribute from each Element node in the collection.
-     *
-     * @param string $name
-     * @return Dom
-     */
-    public function removeAttr(string $name): Dom
-    {
-        /** @var NodeInterface $node */
-        foreach ($this->nodes as $node) {
-            if (!$node instanceof Element) {
-                continue;
-            }
-
-            $node->removeAttribute($name);
-        }
-
-        return $this;
-    }
-
-    /**
-     * Get the combined text contents of each Element node in the collection, including their descendants.
-     * Set the content of each Element node in the collection to the specified text.
-     *
-     * @param string|null $text
-     * @return $this|string
-     */
-    public function text(string $text = null)
-    {
-        if (isset($text)) {
-            foreach ($this->nodes as $node) {
-                if (!$node instanceof Element) {
-                    continue;
-                }
-
-                $node->clear()->insertAfter(new Text($text));
-            }
-
-            return $this;
-        }
-
-        $text = '';
+        $removeClasses = preg_split('/\s+/', $className);
+
+        /** @var NodeInterface $node */
+        foreach ($this->nodes as $node) {
+            if (!$node instanceof Element || !$node->hasAttribute('class')) {
+                continue;
+            }
+
+            // set to the difference between the current classes and the remove ones
+            $currentClasses = preg_split('/\s+/', $node->getAttribute('class'));
+            $node->setAttribute('class', implode(' ', array_diff($currentClasses, $removeClasses)));
+        }
+
+        return $this;
+    }
+
+    /**
+     * Return TRUE if at least one of the Element nodes in the collection has the specified class assigned.
+     *
+     * @param string $className
+     * @return bool
+     */
+    public function hasClass(string $className): bool
+    {
+        /** @var NodeInterface $node */
+        foreach ($this->nodes as $node) {
+            if (!$node instanceof Element || !$node->hasAttribute('class')) {
+                continue;
+            }
+
+            if (SelectorMatcher::containsWord($className, $node->getAttribute('class'))) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * Get the value of an attribute for the first Element node in the collection.
+     * Set the value of an attribute for each Element node in the collection.
+     *
+     * @param string $name
+     * @param string|null $value
+     * @return string|null|$this
+     */
+    public function attr(string $name, string $value = null)
+    {
+        if (isset($value)) {
+            /** @var NodeInterface $node */
+            foreach ($this->nodes as $node) {
+                if (!$node instanceof Element) {
+                    continue;
+                }
+
+                $node->setAttribute($name, $value);
+            }
+
+            return $this;
+        }
+
+        /** @var NodeInterface $node */
+        foreach ($this->nodes as $node) {
+            if (!$node instanceof Element) {
+                continue;
+            }
+
+            return $node->getAttribute($name);
+        }
+
+        return null;
+    }
+
+    /**
+     * Remove an attribute from each Element node in the collection.
+     *
+     * @param string $name
+     * @return Dom
+     */
+    public function removeAttr(string $name): Dom
+    {
+        /** @var NodeInterface $node */
+        foreach ($this->nodes as $node) {
+            if (!$node instanceof Element) {
+                continue;
+            }
+
+            $node->removeAttribute($name);
+        }
+
+        return $this;
+    }
+
+    /**
+     * Get the combined text contents of each Element node in the collection, including their descendants.
+     * Set the content of each Element node in the collection to the specified text.
+     *
+     * @param string|null $text
+     * @return $this|string
+     */
+    public function text(string $text = null)
+    {
+        if (isset($text)) {
+            foreach ($this->nodes as $node) {
+                if (!$node instanceof Element) {
+                    continue;
+                }
+
+                $node->clear()->insertAfter(new Text($text));
+            }
+
+            return $this;
+        }
 
-        foreach ($this->nodes as $node) {
-            if ($node instanceof Text) {
-                $text .= (string) $node;
-            } else if ($node instanceof Element) {
-                /** @var Dom $dom */
-                foreach ((new static($node))->children() as $dom) {
-                    $text .= $dom->text();
-                }
-            }
-        }
-
-        return $text;
-    }
-
-    /**
-     * Get the HTML contents of the first Element node in the collection.
-     * Set the HTML contents of each Element node in the collection.
-     *
-     * @param string|null $html
-     * @return $this|string
-     */
-    public function html(string $html = null)
-    {
-        if (isset($html)) {
-            foreach ($this->nodes as $node) {
-                if (!$node instanceof Element) {
-                    continue;
-                }
-
-                $node->clear();
+        $text = '';
+
+        foreach ($this->nodes as $node) {
+            if ($node instanceof Text) {
+                $text .= (string) $node;
+            } else if ($node instanceof Element) {
+                /** @var Dom $dom */
+                foreach ((new static($node))->children() as $dom) {
+                    $text .= $dom->text();
+                }
+            }
+        }
+
+        return $text;
+    }
+
+    /**
+     * Get the HTML contents of the first Element node in the collection.
+     * Set the HTML contents of each Element node in the collection.
+     *
+     * @param string|null $html
+     * @return $this|string
+     */
+    public function html(string $html = null)
+    {
+        if (isset($html)) {
+            foreach ($this->nodes as $node) {
+                if (!$node instanceof Element) {
+                    continue;
+                }
 
-                foreach ((new static($html))->nodes as $newNode) {
-                    $node->insertAfter($newNode);
-                }
-            }
-
-            return $this;
-        }
-
-        foreach ($this->nodes as $node) {
-            if (!$node instanceof Element) {
-                continue;
-            }
-
-            $html = '';
+                $node->clear();
+
+                foreach ((new static($html))->nodes as $newNode) {
+                    $node->insertAfter($newNode);
+                }
+            }
+
+            return $this;
+        }
+
+        foreach ($this->nodes as $node) {
+            if (!$node instanceof Element) {
+                continue;
+            }
 
-            /** @var NodeInterface $childNode */
-            foreach ($node as $childNode) {
-                $html .= (string) $childNode;
-            }
-
-            return $html;
-        }
-
-        return '';
-    }
-}
+ $html = ''; + + /** @var NodeInterface $childNode */ + foreach ($node as $childNode) { + $html .= (string) $childNode; + } + + return $html; + } + + return ''; + } +}