From f2db151e599f699ee432fcadf4ae872426202dea Mon Sep 17 00:00:00 2001 From: Andres Rey Date: Sun, 2 Sep 2018 20:51:42 +0100 Subject: Add hasAttribute override --- src/Nodes/DOM/DOMNode.php | 1 + src/Nodes/NodeTrait.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) (limited to 'src') diff --git a/src/Nodes/DOM/DOMNode.php b/src/Nodes/DOM/DOMNode.php index f1944c4..7c3c4f3 100644 --- a/src/Nodes/DOM/DOMNode.php +++ b/src/Nodes/DOM/DOMNode.php @@ -6,6 +6,7 @@ use andreskrey\Readability\Nodes\NodeTrait; /** * @method getAttribute($attribute) + * @method hasAttribute($attribute) */ class DOMNode extends \DOMNode { diff --git a/src/Nodes/NodeTrait.php b/src/Nodes/NodeTrait.php index 9f878ce..b4ca746 100644 --- a/src/Nodes/NodeTrait.php +++ b/src/Nodes/NodeTrait.php @@ -163,6 +163,24 @@ trait NodeTrait return ''; } + /** + * Override for native hasAttribute + * + * @see getAttribute + * + * @param $attributeName + * + * @return bool + */ + public function hasAttribute($attributeName) + { + if (!is_null($this->attributes)) { + return parent::hasAttribute($attributeName); + } + + return false; + } + /** * Get the ancestors of the current node. * -- cgit v1.2.3