@@ -302,8 +302,7 @@ public function addFootnotes(\DOMElement $articleContent): void
302302 $ articleLinks = $ articleContent ->getElementsByTagName ('a ' );
303303 $ linkCount = 0 ;
304304
305- for ($ i = 0 ; $ i < $ articleLinks ->length ; ++$ i ) {
306- $ articleLink = $ articleLinks ->item ($ i );
305+ foreach ($ articleLinks as $ articleLink ) {
307306 $ footnoteLink = $ articleLink ->cloneNode (true );
308307 $ refLink = $ this ->dom ->createElement ('a ' );
309308 $ footnote = $ this ->dom ->createElement ('li ' );
@@ -383,8 +382,8 @@ public function prepArticle(\DOMNode $articleContent): void
383382
384383 // Remove service data-candidate attribute.
385384 $ elems = $ xpath ->query ('.//*[@data-candidate] ' , $ articleContent );
386- for ($ i = $ elems-> length - 1 ; $ i >= 0 ; -- $ i ) {
387- $ elems -> item ( $ i ) ->removeAttribute ('data-candidate ' );
385+ foreach ($ elems as $ elem ) {
386+ $ elem ->removeAttribute ('data-candidate ' );
388387 }
389388
390389 // Clean out junk from the article content.
@@ -520,11 +519,12 @@ public function getLinkDensity(\DOMElement $e, bool $excludeExternal = false): f
520519 $ textLength = mb_strlen ($ this ->getInnerText ($ e , true , true ));
521520 $ linkLength = 0 ;
522521
523- for ($ dRe = $ this ->domainRegExp , $ i = 0 , $ il = $ links ->length ; $ i < $ il ; ++$ i ) {
524- if ($ excludeExternal && $ dRe && !preg_match ($ dRe , $ links ->item ($ i )->getAttribute ('href ' ))) {
522+ $ dRe = $ this ->domainRegExp ;
523+ foreach ($ links as $ link ) {
524+ if ($ excludeExternal && $ dRe && !preg_match ($ dRe , $ link ->getAttribute ('href ' ))) {
525525 continue ;
526526 }
527- $ linkLength += mb_strlen ($ this ->getInnerText ($ links -> item ( $ i ) ));
527+ $ linkLength += mb_strlen ($ this ->getInnerText ($ link ));
528528 }
529529
530530 if ($ textLength > 0 && $ linkLength > 0 ) {
@@ -640,15 +640,15 @@ public function cleanConditionally(\DOMElement $e, string $tag): void
640640 $ embedCount = 0 ;
641641 $ embeds = $ node ->getElementsByTagName ('embed ' );
642642
643- for ($ ei = 0 , $ il = $ embeds-> length ; $ ei < $ il ; ++ $ ei ) {
644- if (preg_match ($ this ->regexps ['media ' ], $ embeds -> item ( $ ei ) ->getAttribute ('src ' ))) {
643+ foreach ($ embeds as $ embed ) {
644+ if (preg_match ($ this ->regexps ['media ' ], $ embed ->getAttribute ('src ' ))) {
645645 ++$ embedCount ;
646646 }
647647 }
648648
649649 $ embeds = $ node ->getElementsByTagName ('iframe ' );
650- for ($ ei = 0 , $ il = $ embeds-> length ; $ ei < $ il ; ++ $ ei ) {
651- if (preg_match ($ this ->regexps ['media ' ], $ embeds -> item ( $ ei ) ->getAttribute ('src ' ))) {
650+ foreach ($ embeds as $ embed ) {
651+ if (preg_match ($ this ->regexps ['media ' ], $ embed ->getAttribute ('src ' ))) {
652652 ++$ embedCount ;
653653 }
654654 }
@@ -1015,15 +1015,15 @@ protected function grabArticle(?\DOMElement $page = null)
10151015 * A score is determined by things like number of commas, class names, etc.
10161016 * Maybe eventually link density.
10171017 */
1018- for ($ pt = 0 , $ scored = \count ( $ nodesToScore); $ pt < $ scored ; ++ $ pt ) {
1019- $ ancestors = $ this ->getAncestors ($ nodesToScore [ $ pt ] , 5 );
1018+ foreach ($ nodesToScore as $ nodeToScore ) {
1019+ $ ancestors = $ this ->getAncestors ($ nodeToScore , 5 );
10201020
10211021 // No parent node? Move on...
10221022 if (0 === \count ($ ancestors )) {
10231023 continue ;
10241024 }
10251025
1026- $ innerText = $ this ->getInnerText ($ nodesToScore [ $ pt ] );
1026+ $ innerText = $ this ->getInnerText ($ nodeToScore );
10271027
10281028 // If this paragraph is less than MIN_PARAGRAPH_LENGTH (default:20) characters, don't even count it.
10291029 if (mb_strlen ($ innerText ) < self ::MIN_PARAGRAPH_LENGTH ) {
0 commit comments