22
33namespace Readability ;
44
5+ use DOMElement ;
56use Masterminds \HTML5 ;
67use Psr \Log \LoggerAwareInterface ;
78use Psr \Log \LoggerInterface ;
@@ -164,7 +165,7 @@ public function setLogger(LoggerInterface $logger): void
164165 /**
165166 * Get article title element.
166167 *
167- * @return \ DOMElement
168+ * @return DOMElement
168169 */
169170 public function getTitle ()
170171 {
@@ -174,7 +175,7 @@ public function getTitle()
174175 /**
175176 * Get article content element.
176177 *
177- * @return \ DOMElement
178+ * @return DOMElement
178179 */
179180 public function getContent ()
180181 {
@@ -283,7 +284,7 @@ public function init(): bool
283284 /**
284285 * Run any post-process modifications to article content as necessary.
285286 */
286- public function postProcessContent (\ DOMElement $ articleContent ): void
287+ public function postProcessContent (DOMElement $ articleContent ): void
287288 {
288289 if ($ this ->convertLinksToFootnotes && !preg_match ('/\bwiki/ ' , $ this ->url )) {
289290 $ this ->addFootnotes ($ articleContent );
@@ -295,7 +296,7 @@ public function postProcessContent(\DOMElement $articleContent): void
295296 *
296297 * @see http://www.roughtype.com/archives/2010/05/experiments_in.php
297298 */
298- public function addFootnotes (\ DOMElement $ articleContent ): void
299+ public function addFootnotes (DOMElement $ articleContent ): void
299300 {
300301 $ footnotesWrapper = $ this ->dom ->createElement ('footer ' );
301302 $ footnotesWrapper ->setAttribute ('class ' , 'readability-footnotes ' );
@@ -359,7 +360,7 @@ public function addFootnotes(\DOMElement $articleContent): void
359360 */
360361 public function prepArticle (\DOMNode $ articleContent ): void
361362 {
362- if (!$ articleContent instanceof \ DOMElement) {
363+ if (!$ articleContent instanceof DOMElement) {
363364 return ;
364365 }
365366
@@ -456,9 +457,9 @@ public function prepArticle(\DOMNode $articleContent): void
456457 * Get the inner text of a node.
457458 * This also strips out any excess whitespace to be found.
458459 *
459- * @param \ DOMElement $e
460- * @param bool $normalizeSpaces (default: true)
461- * @param bool $flattenLines (default: false)
460+ * @param DOMElement $e
461+ * @param bool $normalizeSpaces (default: true)
462+ * @param bool $flattenLines (default: false)
462463 */
463464 public function getInnerText ($ e , bool $ normalizeSpaces = true , bool $ flattenLines = false ): string
464465 {
@@ -482,7 +483,7 @@ public function getInnerText($e, bool $normalizeSpaces = true, bool $flattenLine
482483 /**
483484 * Remove the style attribute on every $e and under.
484485 */
485- public function cleanStyles (\ DOMElement $ e ): void
486+ public function cleanStyles (DOMElement $ e ): void
486487 {
487488 if (\is_object ($ e )) {
488489 $ elems = $ e ->getElementsByTagName ('* ' );
@@ -515,7 +516,7 @@ public function getWordCount(string $text): int
515516 * This is the amount of text that is inside a link divided by the total text in the node.
516517 * Can exclude external references to differentiate between simple text and menus/infoblocks.
517518 */
518- public function getLinkDensity (\ DOMElement $ e , bool $ excludeExternal = false ): float
519+ public function getLinkDensity (DOMElement $ e , bool $ excludeExternal = false ): float
519520 {
520521 $ links = $ e ->getElementsByTagName ('a ' );
521522 $ textLength = mb_strlen ($ this ->getInnerText ($ e , true , true ));
@@ -538,7 +539,7 @@ public function getLinkDensity(\DOMElement $e, bool $excludeExternal = false): f
538539 /**
539540 * Get an element relative weight.
540541 */
541- public function getWeight (\ DOMElement $ e ): int
542+ public function getWeight (DOMElement $ e ): int
542543 {
543544 if (!$ this ->flagIsActive (self ::FLAG_WEIGHT_ATTRIBUTES )) {
544545 return 0 ;
@@ -556,7 +557,7 @@ public function getWeight(\DOMElement $e): int
556557 /**
557558 * Remove extraneous break tags from a node.
558559 */
559- public function killBreaks (\ DOMElement $ node ): void
560+ public function killBreaks (DOMElement $ node ): void
560561 {
561562 $ html = $ node ->getInnerHTML ();
562563 $ html = preg_replace ($ this ->regexps ['killBreaks ' ], '<br /> ' , $ html );
@@ -569,7 +570,7 @@ public function killBreaks(\DOMElement $node): void
569570 *
570571 * Updated 2012-09-18 to preserve youtube/vimeo iframes
571572 */
572- public function clean (\ DOMElement $ e , string $ tag ): void
573+ public function clean (DOMElement $ e , string $ tag ): void
573574 {
574575 $ targetList = $ e ->getElementsByTagName ($ tag );
575576 $ isEmbed = ('audio ' === $ tag || 'video ' === $ tag || 'iframe ' === $ tag || 'object ' === $ tag || 'embed ' === $ tag );
@@ -601,7 +602,7 @@ public function clean(\DOMElement $e, string $tag): void
601602 * "Fishy" is an algorithm based on content length, classnames,
602603 * link density, number of images & embeds, etc.
603604 */
604- public function cleanConditionally (\ DOMElement $ e , string $ tag ): void
605+ public function cleanConditionally (DOMElement $ e , string $ tag ): void
605606 {
606607 if (!$ this ->flagIsActive (self ::FLAG_CLEAN_CONDITIONALLY )) {
607608 return ;
@@ -714,7 +715,7 @@ public function cleanConditionally(\DOMElement $e, string $tag): void
714715 /**
715716 * Clean out spurious headers from an Element. Checks things like classnames and link density.
716717 */
717- public function cleanHeaders (\ DOMElement $ e ): void
718+ public function cleanHeaders (DOMElement $ e ): void
718719 {
719720 for ($ headerIndex = 1 ; $ headerIndex < 3 ; ++$ headerIndex ) {
720721 $ headers = $ e ->getElementsByTagName ('h ' . $ headerIndex );
@@ -754,7 +755,7 @@ public function removeFlag(int $flag): void
754755 /**
755756 * Get the article title as an H1.
756757 *
757- * @return \ DOMElement
758+ * @return DOMElement
758759 */
759760 protected function getArticleTitle ()
760761 {
@@ -826,7 +827,7 @@ protected function prepDocument(): void
826827 * Initialize a node with the readability object. Also checks the
827828 * className/id for special names to add to its score.
828829 */
829- protected function initializeNode (\ DOMElement $ node ): void
830+ protected function initializeNode (DOMElement $ node ): void
830831 {
831832 if (!isset ($ node ->tagName )) {
832833 return ;
@@ -894,11 +895,11 @@ protected function initializeNode(\DOMElement $node): void
894895 * Using a variety of metrics (content score, classname, element types), find the content that is
895896 * most likely to be the stuff a user wants to read. Then return it wrapped up in a div.
896897 *
897- * @param \ DOMElement $page
898+ * @param DOMElement $page
898899 *
899- * @return \ DOMElement|false
900+ * @return DOMElement|false
900901 */
901- protected function grabArticle (\ DOMElement $ page = null )
902+ protected function grabArticle (DOMElement $ page = null )
902903 {
903904 if (!$ page ) {
904905 $ page = $ this ->dom ;
@@ -1211,7 +1212,7 @@ protected function grabArticle(\DOMElement $page = null)
12111212 if (0 === strcasecmp ($ tagName , 'td ' ) || 0 === strcasecmp ($ tagName , 'tr ' )) {
12121213 $ up = $ topCandidate ;
12131214
1214- if ($ up ->parentNode instanceof \ DOMElement) {
1215+ if ($ up ->parentNode instanceof DOMElement) {
12151216 $ up = $ up ->parentNode ;
12161217
12171218 if (0 === strcasecmp ($ up ->tagName , 'table ' )) {
@@ -1340,7 +1341,7 @@ protected function grabArticle(\DOMElement $page = null)
13401341 * Get an element weight by attribute.
13411342 * Uses regular expressions to tell if this element looks good or bad.
13421343 */
1343- protected function weightAttribute (\ DOMElement $ element , string $ attribute ): int
1344+ protected function weightAttribute (DOMElement $ element , string $ attribute ): int
13441345 {
13451346 if (!$ element ->hasAttribute ($ attribute )) {
13461347 return 0 ;
@@ -1443,14 +1444,14 @@ private function loadHtml(): void
14431444 libxml_use_internal_errors (false );
14441445 }
14451446
1446- $ this ->dom ->registerNodeClass (' DOMElement ' , ' Readability\JSLikeHTMLElement ' );
1447+ $ this ->dom ->registerNodeClass (DOMElement::class, \ Readability \JSLikeHTMLElement::class );
14471448 }
14481449
1449- private function getAncestors (\ DOMElement $ node , int $ maxDepth = 0 ): array
1450+ private function getAncestors (DOMElement $ node , int $ maxDepth = 0 ): array
14501451 {
14511452 $ ancestors = [];
14521453 $ i = 0 ;
1453- while ($ node ->parentNode instanceof \ DOMElement) {
1454+ while ($ node ->parentNode instanceof DOMElement) {
14541455 $ ancestors [] = $ node ->parentNode ;
14551456 if (++$ i === $ maxDepth ) {
14561457 break ;
@@ -1470,7 +1471,7 @@ private function isPhrasingContent($node): bool
14701471 }, iterator_to_array ($ node ->childNodes )), true ));
14711472 }
14721473
1473- private function hasSingleTagInsideElement (\ DOMElement $ node , string $ tag ): bool
1474+ private function hasSingleTagInsideElement (DOMElement $ node , string $ tag ): bool
14741475 {
14751476 if (1 !== $ node ->childNodes ->length || $ node ->childNodes ->item (0 )->nodeName !== $ tag ) {
14761477 return false ;
@@ -1490,7 +1491,7 @@ private function hasSingleTagInsideElement(\DOMElement $node, string $tag): bool
14901491 * Tidy must be configured to not clean the input for this function to
14911492 * work as expected, see $this->tidy_config['clean']
14921493 */
1493- private function isNodeVisible (\ DOMElement $ node ): bool
1494+ private function isNodeVisible (DOMElement $ node ): bool
14941495 {
14951496 return !($ node ->hasAttribute ('style ' )
14961497 && preg_match ($ this ->regexps ['isNotVisible ' ], $ node ->getAttribute ('style ' ))
0 commit comments