@@ -142,7 +142,7 @@ class Readability implements LoggerAwareInterface
142
142
* @param string $parser Which parser to use for turning raw HTML into a DOMDocument
143
143
* @param bool $useTidy Use tidy
144
144
*/
145
- public function __construct (string $ html , string $ url = null , string $ parser = 'libxml ' , bool $ useTidy = true )
145
+ public function __construct (string $ html , ? string $ url = null , string $ parser = 'libxml ' , bool $ useTidy = true )
146
146
{
147
147
$ this ->url = $ url ;
148
148
$ this ->html = $ html ;
@@ -739,15 +739,15 @@ public function flagIsActive(int $flag): bool
739
739
*/
740
740
public function addFlag (int $ flag ): void
741
741
{
742
- $ this ->flags = $ this -> flags | $ flag ;
742
+ $ this ->flags |= $ flag ;
743
743
}
744
744
745
745
/**
746
746
* Remove a flag.
747
747
*/
748
748
public function removeFlag (int $ flag ): void
749
749
{
750
- $ this ->flags = $ this -> flags & ~$ flag ;
750
+ $ this ->flags &= ~$ flag ;
751
751
}
752
752
753
753
/**
@@ -893,11 +893,9 @@ protected function initializeNode(\DOMElement $node): void
893
893
* Using a variety of metrics (content score, classname, element types), find the content that is
894
894
* most likely to be the stuff a user wants to read. Then return it wrapped up in a div.
895
895
*
896
- * @param \DOMElement $page
897
- *
898
896
* @return \DOMElement|false
899
897
*/
900
- protected function grabArticle (\DOMElement $ page = null )
898
+ protected function grabArticle (? \DOMElement $ page = null )
901
899
{
902
900
if (!$ page ) {
903
901
$ page = $ this ->dom ;
@@ -933,9 +931,9 @@ protected function grabArticle(\DOMElement $page = null)
933
931
// Remove unlikely candidates
934
932
$ unlikelyMatchString = $ node ->getAttribute ('class ' ) . ' ' . $ node ->getAttribute ('id ' ) . ' ' . $ node ->getAttribute ('style ' );
935
933
936
- if (mb_strlen ($ unlikelyMatchString ) > 3 && // don't process "empty" strings
937
- preg_match ($ this ->regexps ['unlikelyCandidates ' ], $ unlikelyMatchString ) &&
938
- !preg_match ($ this ->regexps ['okMaybeItsACandidate ' ], $ unlikelyMatchString )
934
+ if (mb_strlen ($ unlikelyMatchString ) > 3 // don't process "empty" strings
935
+ && preg_match ($ this ->regexps ['unlikelyCandidates ' ], $ unlikelyMatchString )
936
+ && !preg_match ($ this ->regexps ['okMaybeItsACandidate ' ], $ unlikelyMatchString )
939
937
) {
940
938
$ this ->logger ->debug ('Removing unlikely candidate (using conf) ' . $ node ->getNodePath () . ' by " ' . $ unlikelyMatchString . '" ' );
941
939
$ node ->parentNode ->removeChild ($ node );
@@ -1120,9 +1118,11 @@ protected function grabArticle(\DOMElement $page = null)
1120
1118
}
1121
1119
}
1122
1120
1123
- $ topCandidates = array_filter ($ topCandidates , function ($ v , $ idx ) {
1124
- return 0 === $ idx || null !== $ v ;
1125
- }, \ARRAY_FILTER_USE_BOTH );
1121
+ $ topCandidates = array_filter (
1122
+ $ topCandidates ,
1123
+ fn ($ v , $ idx ) => 0 === $ idx || null !== $ v ,
1124
+ \ARRAY_FILTER_USE_BOTH
1125
+ );
1126
1126
$ topCandidate = $ topCandidates [0 ];
1127
1127
1128
1128
/*
@@ -1442,7 +1442,7 @@ private function loadHtml(): void
1442
1442
libxml_use_internal_errors (false );
1443
1443
}
1444
1444
1445
- $ this ->dom ->registerNodeClass (\DOMElement::class, \ Readability \ JSLikeHTMLElement::class);
1445
+ $ this ->dom ->registerNodeClass (\DOMElement::class, JSLikeHTMLElement::class);
1446
1446
}
1447
1447
1448
1448
private function getAncestors (\DOMElement $ node , int $ maxDepth = 0 ): array
@@ -1464,9 +1464,17 @@ private function isPhrasingContent($node): bool
1464
1464
{
1465
1465
return \XML_TEXT_NODE === $ node ->nodeType
1466
1466
|| \in_array (strtoupper ($ node ->nodeName ), $ this ->phrasingElements , true )
1467
- || (\in_array (strtoupper ($ node ->nodeName ), ['A ' , 'DEL ' , 'INS ' ], true ) && !\in_array (false , array_map (function ($ c ) {
1468
- return $ this ->isPhrasingContent ($ c );
1469
- }, iterator_to_array ($ node ->childNodes )), true ));
1467
+ || (
1468
+ \in_array (strtoupper ($ node ->nodeName ), ['A ' , 'DEL ' , 'INS ' ], true )
1469
+ && !\in_array (
1470
+ false ,
1471
+ array_map (
1472
+ fn ($ c ) => $ this ->isPhrasingContent ($ c ),
1473
+ iterator_to_array ($ node ->childNodes )
1474
+ ),
1475
+ true
1476
+ )
1477
+ );
1470
1478
}
1471
1479
1472
1480
private function hasSingleTagInsideElement (\DOMElement $ node , string $ tag ): bool
@@ -1475,10 +1483,10 @@ private function hasSingleTagInsideElement(\DOMElement $node, string $tag): bool
1475
1483
return false ;
1476
1484
}
1477
1485
1478
- $ a = array_filter (iterator_to_array ( $ node -> childNodes ), function ( $ childNode ) {
1479
- return $ childNode instanceof \DOMText &&
1480
- preg_match ($ this ->regexps ['hasContent ' ], $ this ->getInnerText ($ childNode ));
1481
- } );
1486
+ $ a = array_filter (
1487
+ iterator_to_array ( $ node -> childNodes ),
1488
+ fn ( $ childNode ) => $ childNode instanceof \DOMText && preg_match ($ this ->regexps ['hasContent ' ], $ this ->getInnerText ($ childNode ))
1489
+ );
1482
1490
1483
1491
return 0 === \count ($ a );
1484
1492
}
@@ -1491,9 +1499,10 @@ private function hasSingleTagInsideElement(\DOMElement $node, string $tag): bool
1491
1499
*/
1492
1500
private function isNodeVisible (\DOMElement $ node ): bool
1493
1501
{
1494
- return !($ node ->hasAttribute ('style ' )
1495
- && preg_match ($ this ->regexps ['isNotVisible ' ], $ node ->getAttribute ('style ' ))
1502
+ return !(
1503
+ $ node ->hasAttribute ('style ' )
1504
+ && preg_match ($ this ->regexps ['isNotVisible ' ], $ node ->getAttribute ('style ' ))
1496
1505
)
1497
- && !$ node ->hasAttribute ('hidden ' );
1506
+ && !$ node ->hasAttribute ('hidden ' );
1498
1507
}
1499
1508
}
0 commit comments