Skip to content

Commit 62d4289

Browse files
committed
Extract for-iterated items into variables
This simplifies the code a bit and will make it slightly easier in case we decide to switch to `foreach` iteration.
1 parent 891b008 commit 62d4289

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Readability.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ public function clean(\DOMElement $e, string $tag): void
586586
}
587587

588588
// Then check the elements inside this element for the same.
589-
if (preg_match($this->regexps['media'], $targetList->item($y)->getInnerHTML())) {
589+
if (preg_match($this->regexps['media'], $currentItem->getInnerHTML())) {
590590
continue;
591591
}
592592
}
@@ -719,8 +719,9 @@ public function cleanHeaders(\DOMElement $e): void
719719
$headers = $e->getElementsByTagName('h' . $headerIndex);
720720

721721
for ($i = $headers->length - 1; $i >= 0; --$i) {
722-
if ($this->getWeight($headers->item($i)) < 0 || $this->getLinkDensity($headers->item($i)) > 0.33) {
723-
$headers->item($i)->parentNode->removeChild($headers->item($i));
722+
$header = $headers->item($i);
723+
if ($this->getWeight($header) < 0 || $this->getLinkDensity($header) > 0.33) {
724+
$header->parentNode->removeChild($header);
724725
}
725726
}
726727
}
@@ -812,12 +813,14 @@ protected function prepDocument(): void
812813
// Remove all style tags in head.
813814
$styleTags = $this->dom->getElementsByTagName('style');
814815
for ($i = $styleTags->length - 1; $i >= 0; --$i) {
815-
$styleTags->item($i)->parentNode->removeChild($styleTags->item($i));
816+
$styleTag = $styleTags->item($i);
817+
$styleTag->parentNode->removeChild($styleTag);
816818
}
817819

818820
$linkTags = $this->dom->getElementsByTagName('link');
819821
for ($i = $linkTags->length - 1; $i >= 0; --$i) {
820-
$linkTags->item($i)->parentNode->removeChild($linkTags->item($i));
822+
$linkTag = $linkTags->item($i);
823+
$linkTag->parentNode->removeChild($linkTag);
821824
}
822825
}
823826

0 commit comments

Comments
 (0)