@@ -302,8 +302,7 @@ public function addFootnotes(\DOMElement $articleContent): void
302
302
$ articleLinks = $ articleContent ->getElementsByTagName ('a ' );
303
303
$ linkCount = 0 ;
304
304
305
- for ($ i = 0 ; $ i < $ articleLinks ->length ; ++$ i ) {
306
- $ articleLink = $ articleLinks ->item ($ i );
305
+ foreach ($ articleLinks as $ articleLink ) {
307
306
$ footnoteLink = $ articleLink ->cloneNode (true );
308
307
$ refLink = $ this ->dom ->createElement ('a ' );
309
308
$ footnote = $ this ->dom ->createElement ('li ' );
@@ -383,8 +382,8 @@ public function prepArticle(\DOMNode $articleContent): void
383
382
384
383
// Remove service data-candidate attribute.
385
384
$ 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 ' );
388
387
}
389
388
390
389
// Clean out junk from the article content.
@@ -520,11 +519,12 @@ public function getLinkDensity(\DOMElement $e, bool $excludeExternal = false): f
520
519
$ textLength = mb_strlen ($ this ->getInnerText ($ e , true , true ));
521
520
$ linkLength = 0 ;
522
521
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 ' ))) {
525
525
continue ;
526
526
}
527
- $ linkLength += mb_strlen ($ this ->getInnerText ($ links -> item ( $ i ) ));
527
+ $ linkLength += mb_strlen ($ this ->getInnerText ($ link ));
528
528
}
529
529
530
530
if ($ textLength > 0 && $ linkLength > 0 ) {
@@ -640,15 +640,15 @@ public function cleanConditionally(\DOMElement $e, string $tag): void
640
640
$ embedCount = 0 ;
641
641
$ embeds = $ node ->getElementsByTagName ('embed ' );
642
642
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 ' ))) {
645
645
++$ embedCount ;
646
646
}
647
647
}
648
648
649
649
$ 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 ' ))) {
652
652
++$ embedCount ;
653
653
}
654
654
}
@@ -1018,15 +1018,15 @@ protected function grabArticle(?\DOMElement $page = null)
1018
1018
* A score is determined by things like number of commas, class names, etc.
1019
1019
* Maybe eventually link density.
1020
1020
*/
1021
- for ($ pt = 0 , $ scored = \count ( $ nodesToScore); $ pt < $ scored ; ++ $ pt ) {
1022
- $ ancestors = $ this ->getAncestors ($ nodesToScore [ $ pt ] , 5 );
1021
+ foreach ($ nodesToScore as $ nodeToScore ) {
1022
+ $ ancestors = $ this ->getAncestors ($ nodeToScore , 5 );
1023
1023
1024
1024
// No parent node? Move on...
1025
1025
if (0 === \count ($ ancestors )) {
1026
1026
continue ;
1027
1027
}
1028
1028
1029
- $ innerText = $ this ->getInnerText ($ nodesToScore [ $ pt ] );
1029
+ $ innerText = $ this ->getInnerText ($ nodeToScore );
1030
1030
1031
1031
// If this paragraph is less than MIN_PARAGRAPH_LENGTH (default:20) characters, don't even count it.
1032
1032
if (mb_strlen ($ innerText ) < self ::MIN_PARAGRAPH_LENGTH ) {
0 commit comments