From 3724316efee290091c2c87d6c13f6f0d70995439 Mon Sep 17 00:00:00 2001 From: "FiveFilters.org" Date: Tue, 31 Aug 2021 23:54:08 +0200 Subject: Adhere to standard code style --- src/Readability.php | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'src/Readability.php') diff --git a/src/Readability.php b/src/Readability.php index cf2faaf..5c8fb84 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -357,7 +357,7 @@ class Readability { $scripts = $this->_getAllNodesWithTag($dom, ['script']); - $jsonLdElement = $this->findNode($scripts, function($el) { + $jsonLdElement = $this->findNode($scripts, function ($el) { return $el->getAttribute('type') === 'application/ld+json'; }); @@ -407,10 +407,10 @@ class Readability isset($parsed['author'][0]['name']) && is_string($parsed['author'][0]['name']) ) { - $metadata['byline'] = array_filter($parsed['author'], function($author) { + $metadata['byline'] = array_filter($parsed['author'], function ($author) { return is_array($author) && isset($author['name']) && is_string($author['name']); }); - $metadata['byline'] = array_map(function($author) { + $metadata['byline'] = array_map(function ($author) { return trim($author['name']); }, $metadata['byline']); $metadata['byline'] = implode(', ', $metadata['byline']); @@ -432,7 +432,7 @@ class Readability // The try-catch blocks are from the JS version. Not sure if there's anything // here in the PHP version that would trigger an error or exception, so perhaps we can // remove the try-catch blocks here (or at least translate errors to exceptions for this bit) - $this->logger->debug('[JSON-LD] Error parsing: '.$err->getMessage()); + $this->logger->debug('[JSON-LD] Error parsing: ' . $err->getMessage()); } } return []; @@ -694,7 +694,7 @@ class Readability * I can assure you it works properly if you let the code run. */ if (preg_match('/ [\|\-\\\\\/>»] /i', $curTitle)) { - $titleHadHierarchicalSeparators = (bool)preg_match('/ [\\\\\/>»] /', $curTitle); + $titleHadHierarchicalSeparators = (bool) preg_match('/ [\\\\\/>»] /', $curTitle); $curTitle = preg_replace('/(.*)[\|\-\\\\\/>»] .*/i', '$1', $originalTitle); $this->logger->info(sprintf('[Metadata] Found hierarchical separators in title, new title is: \'%s\'', $curTitle)); @@ -827,7 +827,7 @@ class Readability $pathBase = parse_url($url, PHP_URL_SCHEME) . '://' . parse_url($url, PHP_URL_HOST) . $this->baseURI; } else { // Otherwise just prepend the base to the actual path - $pathBase = parse_url($url, PHP_URL_SCHEME) . '://' . parse_url($url, PHP_URL_HOST) . dirname(parse_url($url, PHP_URL_PATH)) . '/' . rtrim($this->baseURI, '/') . '/'; + $pathBase = parse_url($url, PHP_URL_SCHEME) . '://' . parse_url($url, PHP_URL_HOST) . dirname(parse_url($url, PHP_URL_PATH)) . '/'.rtrim($this->baseURI, '/') . '/'; } } else { $pathBase = parse_url($url, PHP_URL_SCHEME) . '://' . parse_url($url, PHP_URL_HOST) . dirname(parse_url($url, PHP_URL_PATH)) . '/'; @@ -890,7 +890,7 @@ class Readability $shouldRemoveTitleHeader = false; $node = NodeUtility::removeAndGetNext($node); continue; - } + } // Remove unlikely candidates if ($stripUnlikelyCandidates) { @@ -912,7 +912,7 @@ class Readability $this->logger->debug(sprintf('Removing content with role %s - %s', $node->getAttribute('role'), $matchString)); $node = NodeUtility::removeAndGetNext($node); continue; - } + } // Remove DIV, SECTION, and HEADER nodes without any content(e.g. text, image, video, or iframe). if (($node->nodeName === 'div' || $node->nodeName === 'section' || $node->nodeName === 'header' || @@ -1067,10 +1067,10 @@ class Readability } $htmlEscapeMap = $this->htmlEscapeMap; - $str = preg_replace_callback('/&(quot|amp|apos|lt|gt);/', function($tag) use($htmlEscapeMap) { + $str = preg_replace_callback('/&(quot|amp|apos|lt|gt);/', function ($tag) use ($htmlEscapeMap) { return $htmlEscapeMap[$tag[1]]; }, $str); - $str = preg_replace_callback('/&#(?:x([0-9a-z]{1,4})|([0-9]{1,4}));/i', function($matches) { + $str = preg_replace_callback('/&#(?:x([0-9a-z]{1,4})|([0-9]{1,4}));/i', function ($matches) { $hex = $matches[1]; $numStr = $matches[2]; if ($hex !== '') { @@ -1101,19 +1101,19 @@ class Readability return $this->isSingleImage($node->children()->item(0)); } - /** - * Find all