summaryrefslogtreecommitdiff
path: root/src/Nodes
diff options
context:
space:
mode:
authorAndres Rey <[email protected]>2019-06-17 23:09:25 +0100
committerAndres Rey <[email protected]>2019-06-17 23:09:25 +0100
commita1243b7fa248f5abf197c4ff8c406d75dfdbdc6e (patch)
tree3b63985cfda4fc96c00ea8a7881815fe71df205b /src/Nodes
parent544d1fd99185064af82d114d24cad73e63686810 (diff)
Make DOMNodeList more DOMNodeList...y
Diffstat (limited to 'src/Nodes')
-rw-r--r--src/Nodes/DOM/DOMNodeList.php51
-rw-r--r--src/Nodes/NodeTrait.php2
2 files changed, 15 insertions, 38 deletions
diff --git a/src/Nodes/DOM/DOMNodeList.php b/src/Nodes/DOM/DOMNodeList.php
index 28d4d42..6a53fdf 100644
--- a/src/Nodes/DOM/DOMNodeList.php
+++ b/src/Nodes/DOM/DOMNodeList.php
@@ -14,7 +14,7 @@ namespace andreskrey\Readability\Nodes\DOM;
*
* @package andreskrey\Readability\Nodes\DOM
*/
-class DOMNodeList implements \ArrayAccess, \Countable, \IteratorAggregate
+class DOMNodeList implements \Countable, \IteratorAggregate
{
/**
* @var array
@@ -42,11 +42,11 @@ class DOMNodeList implements \ArrayAccess, \Countable, \IteratorAggregate
}
/**
- * @param \DOMNode $node
+ * @param DOMNode|DOMElement|DOMComment $node
*
* @return DOMNodeList
*/
- public function add(\DOMNode $node)
+ public function add($node)
{
$this->items[] = $node;
$this->length++;
@@ -55,54 +55,31 @@ class DOMNodeList implements \ArrayAccess, \Countable, \IteratorAggregate
}
/**
- * @return int|void
- */
- public function count()
- {
- return $this->length;
- }
-
- /**
- * To make it compatible with iterator_to_array() function
+ * @param int $offset
*
- * {@inheritDoc}
+ * @return DOMNode|DOMElement|DOMComment
*/
- public function getIterator()
- {
- return new \ArrayIterator($this->items);
- }
-
- /**
- * {@inheritDoc}
- */
- public function offsetExists($offset)
- {
- return isset($this->items[$offset]);
- }
-
- /**
- * {@inheritDoc}
- */
- public function offsetGet($offset)
+ public function item(int $offset)
{
return $this->items[$offset];
}
/**
- * {@inheritDoc}
+ * @return int|void
*/
- public function offsetSet($offset, $value)
+ public function count(): int
{
- $this->items[$offset] = $value;
- $this->length = count($this->items);
+ return $this->length;
}
/**
+ * To make it compatible with iterator_to_array() function
+ *
* {@inheritDoc}
*/
- public function offsetUnset($offset)
+ public function getIterator(): \ArrayIterator
{
- unset($this->items[$offset]);
- $this->length--;
+ return new \ArrayIterator($this->items);
}
+
}
diff --git a/src/Nodes/NodeTrait.php b/src/Nodes/NodeTrait.php
index 2b58167..dfff138 100644
--- a/src/Nodes/NodeTrait.php
+++ b/src/Nodes/NodeTrait.php
@@ -422,7 +422,7 @@ trait NodeTrait
public function hasSingleTagInsideElement($tag)
{
// There should be exactly 1 element child with given tag
- if (count($children = NodeUtility::filterTextNodes($this->childNodes)) !== 1 || $children[0]->nodeName !== $tag) {
+ if (count($children = NodeUtility::filterTextNodes($this->childNodes)) !== 1 || $children->item(0)->nodeName !== $tag) {
return false;
}