Skip to content

Commit

Permalink
Merge pull request #98 from DieterHolvoet/fix-no-parent
Browse files Browse the repository at this point in the history
Fix error in parent() method if no parent node
  • Loading branch information
voku authored May 25, 2024
2 parents 4e8e9d4 + ec3b25e commit 46dc4cd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/voku/helper/SimpleHtmlDom.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,11 +684,15 @@ public function nextNonWhitespaceSibling()
/**
* Returns the parent of node.
*
* @return SimpleHtmlDomInterface
* @return SimpleHtmlDomInterface|null
*/
public function parentNode(): SimpleHtmlDomInterface
public function parentNode(): ?SimpleHtmlDomInterface
{
return new static($this->node->parentNode);
if ($node = $this->node->parentNode) {
return new static($node);
}

return null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/voku/helper/SimpleHtmlDomBlank.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ public function previousNonWhitespaceSibling()
/**
* Returns the parent of node.
*
* @return SimpleHtmlDomInterface
* @return SimpleHtmlDomInterface|null
*/
public function parentNode(): SimpleHtmlDomInterface
public function parentNode(): ?SimpleHtmlDomInterface
{
return new static();
}
Expand Down
4 changes: 2 additions & 2 deletions src/voku/helper/SimpleHtmlDomInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ public function previousNonWhitespaceSibling();
/**
* Returns the parent of node.
*
* @return SimpleHtmlDomInterface
* @return SimpleHtmlDomInterface|null
*/
public function parentNode(): self;
public function parentNode(): ?self;

/**
* Returns the previous sibling of node.
Expand Down

0 comments on commit 46dc4cd

Please sign in to comment.