diff options
author | Andres Rey <[email protected]> | 2016-11-04 19:06:20 +0000 |
---|---|---|
committer | StyleCI Bot <[email protected]> | 2016-11-04 19:06:20 +0000 |
commit | 0b45ceb23a135364275ad5ce20045d0a204a5e57 (patch) | |
tree | 6e6a4b40288386bff0c0230f060a2b91f14a4531 /src | |
parent | 891568a88b24b82d1388c6fe73b3722980bfc1d7 (diff) |
Applied fixes from StyleCI
Diffstat (limited to 'src')
-rw-r--r-- | src/Configuration.php | 6 | ||||
-rw-r--r-- | src/Environment.php | 4 | ||||
-rw-r--r-- | src/HTMLParser.php | 13 | ||||
-rw-r--r-- | src/Readability.php | 15 |
4 files changed, 22 insertions, 16 deletions
diff --git a/src/Configuration.php b/src/Configuration.php index 1424b14..d2fa6a7 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -9,7 +9,7 @@ class Configuration /** * @param array $config */ - public function __construct(array $config = array()) + public function __construct(array $config = []) { $this->config = $config; } @@ -17,7 +17,7 @@ class Configuration /** * @param array $config */ - public function merge(array $config = array()) + public function merge(array $config = []) { $this->config = array_replace_recursive($this->config, $config); } @@ -25,7 +25,7 @@ class Configuration /** * @param array $config */ - public function replace(array $config = array()) + public function replace(array $config = []) { $this->config = $config; } diff --git a/src/Environment.php b/src/Environment.php index 9f3dc86..6e88783 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -9,7 +9,7 @@ final class Environment */ protected $config; - public function __construct(array $config = array()) + public function __construct(array $config = []) { $this->config = new Configuration($config); } @@ -27,7 +27,7 @@ final class Environment * * @return Environment */ - public static function createDefaultEnvironment(array $config = array()) + public static function createDefaultEnvironment(array $config = []) { $environment = new static($config); diff --git a/src/HTMLParser.php b/src/HTMLParser.php index 5a684a5..2c1d7cb 100644 --- a/src/HTMLParser.php +++ b/src/HTMLParser.php @@ -69,19 +69,20 @@ class HTMLParser 'section', 'p', // TODO, check if this is correct, #text elements do not exist in js - '#text' + '#text', ]; /** * Constructor. + * * @param array $options Options to override the default ones */ public function __construct(array $options = []) { - $defaults = array( + $defaults = [ 'maxTopCandidates' => 5, // Max amount of top level candidates 'articleByLine' => null, - ); + ]; $this->environment = Environment::createDefaultEnvironment($defaults); @@ -246,7 +247,6 @@ class HTMLParser private function getNodes(Readability $node) { while ($node) { - $matchString = $node->getAttribute('class') . ' ' . $node->getAttribute('id'); // Check to see if this node is a byline, and remove it if it is. @@ -405,7 +405,7 @@ class HTMLParser $scoreThreshold = $lastScore / 3; while ($parentOfTopCandidate) { - /** @var Readability $parentOfTopCandidate */ + /* @var Readability $parentOfTopCandidate */ $parentScore = $parentOfTopCandidate->getContentScore(); if ($parentScore < $scoreThreshold) { break; @@ -491,6 +491,7 @@ class HTMLParser if ($rel === 'author' || preg_match($this->regexps['byline'], $matchString) && $this->isValidByline($node->getTextContent())) { $this->metadata['byline'] = trim($node->getTextContent()); + return true; } @@ -501,8 +502,10 @@ class HTMLParser { if (gettype($text) == 'string') { $byline = trim($text); + return (strlen($byline) > 0) && (strlen($text) < 100); } + return false; } diff --git a/src/Readability.php b/src/Readability.php index 39e1a28..ed1d2be 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -146,8 +146,9 @@ class Readability extends Element implements ReadabilityInterface } else { $links = []; foreach ($this->node->getElementsByTagName('a') as $link) { - $links[] = new Readability($link); - }; + $links[] = new self($link); + } + return $links; } } @@ -259,7 +260,7 @@ class Readability extends Element implements ReadabilityInterface if (get_class($this->node) !== 'DOMDocument') { // To prevent the -0 value - $this->contentScore = ($score === (double)-0) ? 0 : $score; + $this->contentScore = ($score === (float) -0) ? 0 : $score; // Set score in an attribute of the tag to prevent losing it while creating new Readability objects. $this->node->setAttribute('readability', $this->contentScore); @@ -283,11 +284,12 @@ class Readability extends Element implements ReadabilityInterface if ($normalize) { $nodeValue = trim(preg_replace('/\s{2,}/', ' ', $nodeValue)); } + return $nodeValue; } /** - * Sets the node name + * Sets the node name. * * @param string $value */ @@ -297,7 +299,7 @@ class Readability extends Element implements ReadabilityInterface } /** - * Returns the current DOMNode + * Returns the current DOMNode. * * @return \DOMNode */ @@ -310,12 +312,13 @@ class Readability extends Element implements ReadabilityInterface { $nextNode = $this->getNextNode($node, true); $nextNode->node->parentNode->removeChild($node->node); + return $nextNode; } public function getNextNode($originalNode, $ignoreSelfAndKids = false) { - /** + /* * Traverse the DOM from node to node, starting at the node passed in. * Pass true for the second parameter to indicate this node itself * (and its kids) are going away, and we want the next node over. |