summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Nodes/DOM/DOMNodeList.php51
-rw-r--r--src/Nodes/NodeTrait.php2
-rw-r--r--src/Readability.php2
3 files changed, 16 insertions, 39 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;
}
diff --git a/src/Readability.php b/src/Readability.php
index 8890183..220395e 100644
--- a/src/Readability.php
+++ b/src/Readability.php
@@ -735,7 +735,7 @@ class Readability
*/
if ($node->hasSingleTagInsideElement('p') && $node->getLinkDensity() < 0.25) {
$this->logger->debug(sprintf('[Get Nodes] Found DIV with a single P node, removing DIV. Node content is: \'%s\'', substr($node->nodeValue, 0, 128)));
- $pNode = NodeUtility::filterTextNodes($node->childNodes)[0];
+ $pNode = NodeUtility::filterTextNodes($node->childNodes)->item(0);
$node->parentNode->replaceChild($pNode, $node);
$node = $pNode;
$elementsToScore[] = $node;