Replace isset with clearer null check

`isset` does two things: it checks if the entity resulting from the chain of accessors is defined, and if it is not `null`.
We know that the properties are always defined so we can just replace those `isset`s with `null` checks.
This will allow us to reason about the code more clearly.
pull/93/head
Jan Tojnar 1 year ago
parent c6d0eb2345
commit 6a7f008f72
  1. 15
      src/Readability.php

@ -308,7 +308,7 @@ class Readability implements LoggerAwareInterface
{
$this->loadHtml();
if (!isset($this->dom->documentElement)) {
if (null === $this->dom || null === $this->dom->documentElement) {
return false;
}
@ -400,7 +400,7 @@ class Readability implements LoggerAwareInterface
$refLink = $this->dom->createElement('a');
$footnote = $this->dom->createElement('li');
$linkDomain = @parse_url($footnoteLink->getAttribute('href'), \PHP_URL_HOST);
if (!$linkDomain && isset($this->url)) {
if (!$linkDomain && null !== $this->url) {
$linkDomain = @parse_url($this->url, \PHP_URL_HOST);
}
@ -1223,15 +1223,16 @@ class Readability implements LoggerAwareInterface
$topCandidate = $this->dom->createElement('div');
if ($page instanceof \DOMDocument) {
if (!isset($page->documentElement)) {
$documentElement = $page->documentElement;
if (null === $documentElement) {
// we don't have a body either? what a mess! :)
$this->logger->debug('The page has no body!');
} else {
$this->logger->debug('Setting body to a raw HTML of original page!');
$topCandidate->setInnerHtml($page->documentElement->getInnerHTML());
$page->documentElement->setInnerHtml('');
$topCandidate->setInnerHtml($documentElement->getInnerHTML());
$documentElement->setInnerHtml('');
$this->reinitBody();
$page->documentElement->appendChild($topCandidate);
$documentElement->appendChild($topCandidate);
}
} else {
$topCandidate->setInnerHtml($page->getInnerHTML());
@ -1457,7 +1458,7 @@ class Readability implements LoggerAwareInterface
*/
protected function reinitBody(): void
{
if (!isset($this->body->childNodes)) {
if (null === $this->body) {
$this->body = $this->dom->createElement('body');
$this->body->setInnerHtml($this->bodyCache);
}

Loading…
Cancel
Save