summaryrefslogtreecommitdiff
path: root/src/Nodes
diff options
context:
space:
mode:
authorAndres Rey <[email protected]>2018-09-02 10:15:34 +0100
committerAndres Rey <[email protected]>2018-09-02 10:15:34 +0100
commit473a5b2fb98b962428bc5a892784e214e62b69cd (patch)
tree6e9544f408898dec35b7355e2e059eb483bb2e58 /src/Nodes
parentef57e870f9cfd1bec25028abd2c1e9dcb6a99126 (diff)
Rename hasSinglePNode to hasSingleTagInsideElement and accept tag as parameter
Diffstat (limited to 'src/Nodes')
-rw-r--r--src/Nodes/NodeTrait.php20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/Nodes/NodeTrait.php b/src/Nodes/NodeTrait.php
index 9f24abc..4e54566 100644
--- a/src/Nodes/NodeTrait.php
+++ b/src/Nodes/NodeTrait.php
@@ -375,26 +375,26 @@ trait NodeTrait
* Useful to convert <div><p> nodes to a single <p> node and avoid confusing the scoring system since div with p
* tags are, in practice, paragraphs.
*
- * @param DOMNode $node
+ * @param $tag string Name of tag
*
* @return bool
*/
- public function hasSinglePNode()
+ public function hasSingleTagInsideElement($tag)
{
- // There should be exactly 1 element child which is a P:
- if (count($children = $this->getChildren(true)) !== 1 || $children[0]->nodeName !== 'p') {
+ // There should be exactly 1 element child with given tag
+ if (count($children = $this->getChildren(true)) !== 1 || $children[0]->nodeName !== $tag) {
return false;
}
- // And there should be no text nodes with real content (param true on ->getChildren)
- foreach ($children as $child) {
- /** @var $child DOMNode */
- if ($child->nodeType === XML_TEXT_NODE && !preg_match('/\S$/', $child->getTextContent())) {
+ // And there should be no text nodes with real content
+ return array_reduce($children, function ($carry, $child) {
+ if (!$carry === false) {
return false;
}
- }
- return true;
+ /** @var $child DOMNode */
+ return !($child->nodeType === XML_TEXT_NODE && !preg_match('/\S$/', $child->getTextContent()));
+ });
}
/**