@@ -142,7 +142,7 @@ class Readability implements LoggerAwareInterface
142142 * @param string $parser Which parser to use for turning raw HTML into a DOMDocument
143143 * @param bool $useTidy Use tidy
144144 */
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 )
146146 {
147147 $ this ->url = $ url ;
148148 $ this ->html = $ html ;
@@ -739,15 +739,15 @@ public function flagIsActive(int $flag): bool
739739 */
740740 public function addFlag (int $ flag ): void
741741 {
742- $ this ->flags = $ this -> flags | $ flag ;
742+ $ this ->flags |= $ flag ;
743743 }
744744
745745 /**
746746 * Remove a flag.
747747 */
748748 public function removeFlag (int $ flag ): void
749749 {
750- $ this ->flags = $ this -> flags & ~$ flag ;
750+ $ this ->flags &= ~$ flag ;
751751 }
752752
753753 /**
@@ -893,11 +893,9 @@ protected function initializeNode(\DOMElement $node): void
893893 * Using a variety of metrics (content score, classname, element types), find the content that is
894894 * most likely to be the stuff a user wants to read. Then return it wrapped up in a div.
895895 *
896- * @param \DOMElement $page
897- *
898896 * @return \DOMElement|false
899897 */
900- protected function grabArticle (\DOMElement $ page = null )
898+ protected function grabArticle (? \DOMElement $ page = null )
901899 {
902900 if (!$ page ) {
903901 $ page = $ this ->dom ;
@@ -933,9 +931,9 @@ protected function grabArticle(\DOMElement $page = null)
933931 // Remove unlikely candidates
934932 $ unlikelyMatchString = $ node ->getAttribute ('class ' ) . ' ' . $ node ->getAttribute ('id ' ) . ' ' . $ node ->getAttribute ('style ' );
935933
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 )
939937 ) {
940938 $ this ->logger ->debug ('Removing unlikely candidate (using conf) ' . $ node ->getNodePath () . ' by " ' . $ unlikelyMatchString . '" ' );
941939 $ node ->parentNode ->removeChild ($ node );
@@ -1120,9 +1118,11 @@ protected function grabArticle(\DOMElement $page = null)
11201118 }
11211119 }
11221120
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+ );
11261126 $ topCandidate = $ topCandidates [0 ];
11271127
11281128 /*
@@ -1442,7 +1442,7 @@ private function loadHtml(): void
14421442 libxml_use_internal_errors (false );
14431443 }
14441444
1445- $ this ->dom ->registerNodeClass (\DOMElement::class, \ Readability \ JSLikeHTMLElement::class);
1445+ $ this ->dom ->registerNodeClass (\DOMElement::class, JSLikeHTMLElement::class);
14461446 }
14471447
14481448 private function getAncestors (\DOMElement $ node , int $ maxDepth = 0 ): array
@@ -1464,9 +1464,17 @@ private function isPhrasingContent($node): bool
14641464 {
14651465 return \XML_TEXT_NODE === $ node ->nodeType
14661466 || \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+ );
14701478 }
14711479
14721480 private function hasSingleTagInsideElement (\DOMElement $ node , string $ tag ): bool
@@ -1475,10 +1483,10 @@ private function hasSingleTagInsideElement(\DOMElement $node, string $tag): bool
14751483 return false ;
14761484 }
14771485
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+ );
14821490
14831491 return 0 === \count ($ a );
14841492 }
@@ -1491,9 +1499,10 @@ private function hasSingleTagInsideElement(\DOMElement $node, string $tag): bool
14911499 */
14921500 private function isNodeVisible (\DOMElement $ node ): bool
14931501 {
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 ' ))
14961505 )
1497- && !$ node ->hasAttribute ('hidden ' );
1506+ && !$ node ->hasAttribute ('hidden ' );
14981507 }
14991508}
0 commit comments