Skip to content

Commit

Permalink
Extract for-iterated items into variables
Browse files Browse the repository at this point in the history
This simplifies the code a bit and will make it slightly easier in case we decide to switch to `foreach` iteration.
  • Loading branch information
jtojnar committed Mar 17, 2024
1 parent f6933aa commit 9173e41
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Readability.php
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,9 @@ public function cleanHeaders(\DOMElement $e): void
$headers = $e->getElementsByTagName('h' . $headerIndex);

for ($i = $headers->length - 1; $i >= 0; --$i) {
if ($this->getWeight($headers->item($i)) < 0 || $this->getLinkDensity($headers->item($i)) > 0.33) {
$headers->item($i)->parentNode->removeChild($headers->item($i));
$header = $headers->item($i);
if ($this->getWeight($header) < 0 || $this->getLinkDensity($header) > 0.33) {
$header->parentNode->removeChild($header);
}
}
}
Expand Down Expand Up @@ -812,12 +813,14 @@ protected function prepDocument(): void
// Remove all style tags in head.
$styleTags = $this->dom->getElementsByTagName('style');
for ($i = $styleTags->length - 1; $i >= 0; --$i) {
$styleTags->item($i)->parentNode->removeChild($styleTags->item($i));
$styleTag = $styleTags->item($i);
$styleTag->parentNode->removeChild($styleTag);
}

$linkTags = $this->dom->getElementsByTagName('link');
for ($i = $linkTags->length - 1; $i >= 0; --$i) {
$linkTags->item($i)->parentNode->removeChild($linkTags->item($i));
$linkTag = $linkTags->item($i);
$linkTag->parentNode->removeChild($linkTag);
}
}

Expand Down

0 comments on commit 9173e41

Please sign in to comment.