summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndres Rey <[email protected]>2017-11-12 20:31:38 +0000
committerGitHub <[email protected]>2017-11-12 20:31:38 +0000
commitab14e4beb6e94f56a27a215a078d608558f3db2d (patch)
tree8f802b0779f286a8059a12d90ae51450bf656db9
parent70ca50ce2d395bb924b5481ff6d7815317e132a1 (diff)
parent52040373716eb2bd343792636bc2bacad2eca3b7 (diff)
Merge pull request #26 from andreskrey/analysis-qJaM2b
Apply fixes from StyleCI
-rw-r--r--src/HTMLParser.php19
-rw-r--r--src/Readability.php15
2 files changed, 18 insertions, 16 deletions
diff --git a/src/HTMLParser.php b/src/HTMLParser.php
index cc5c1be..84d174e 100644
--- a/src/HTMLParser.php
+++ b/src/HTMLParser.php
@@ -17,7 +17,8 @@ class HTMLParser
private $dom = null;
/**
- * TODO Make this an object? Instead of a dumb array
+ * TODO Make this an object? Instead of a dumb array.
+ *
* @var array
*/
private $metadata = [];
@@ -578,7 +579,7 @@ class HTMLParser
if (count(preg_split('/\s+/', $curTitle)) < 3) {
$curTitle = preg_replace('/[^\|\-\\\\\/>»]*[\|\-\\\\\/>»](.*)/i', '$1', $originalTitle);
}
- } else if (strpos($curTitle, ': ') !== false) {
+ } elseif (strpos($curTitle, ': ') !== false) {
// Check if we have an heading containing this exact string, so we
// could assume it's the full title.
$match = false;
@@ -595,10 +596,11 @@ class HTMLParser
$curTitle = substr($originalTitle, strrpos($originalTitle, ':') + 1);
// If the title is now too short, try the first colon instead:
- if (count(preg_split('/\s+/', $curTitle)) < 3)
+ if (count(preg_split('/\s+/', $curTitle)) < 3) {
$curTitle = substr($originalTitle, strpos($originalTitle, ':') + 1);
+ }
}
- } else if (mb_strlen($curTitle) > 150 || mb_strlen($curTitle) < 15) {
+ } elseif (mb_strlen($curTitle) > 150 || mb_strlen($curTitle) < 15) {
$hOnes = $this->dom->getElementsByTagName('h1');
if ($hOnes->length === 1) {
@@ -681,7 +683,6 @@ class HTMLParser
continue;
}
-
if (in_array(strtolower($node->getTagName()), $this->defaultTagsToScore)) {
$elementsToScore[] = $node;
}
@@ -1088,7 +1089,7 @@ class HTMLParser
/**
* Look for 'data' (as opposed to 'layout') tables, for which we use
* similar checks as
- * https://dxr.mozilla.org/mozilla-central/rev/71224049c0b52ab190564d3ea0eab089a159a4cf/accessible/html/HTMLTableAccessible.cpp#920
+ * https://dxr.mozilla.org/mozilla-central/rev/71224049c0b52ab190564d3ea0eab089a159a4cf/accessible/html/HTMLTableAccessible.cpp#920.
*
* TODO To be moved to Readability. WARNING: check if we actually keep the "readabilityDataTable" param and
* maybe switch to a readability data-tag?
@@ -1103,7 +1104,7 @@ class HTMLParser
foreach ($tables as $table) {
/** @var \DOMElement $table */
$role = $table->getAttribute('role');
- if ($role === "presentation") {
+ if ($role === 'presentation') {
$table->readabilityDataTable = false;
continue;
}
@@ -1150,6 +1151,7 @@ class HTMLParser
/**
* Return an array indicating how many rows and columns this table has.
+ *
* @param \DOMElement $table
*
* @return array
@@ -1197,7 +1199,7 @@ class HTMLParser
/**
* Remove the style attribute on every e and under.
- * TODO: To be moved to Readability
+ * TODO: To be moved to Readability.
*
* @param $node \DOMDocument|\DOMNode
**/
@@ -1235,6 +1237,7 @@ class HTMLParser
* TODO To be moved to readability
*
* @param string $regex Match id/class combination.
+ *
* @return void
**/
public function _cleanMatchedNodes($node, $regex)
diff --git a/src/Readability.php b/src/Readability.php
index c8ce01a..bf8cdf8 100644
--- a/src/Readability.php
+++ b/src/Readability.php
@@ -419,7 +419,7 @@ class Readability extends Element implements ReadabilityInterface
*
* @param Readability $newNode
*/
- public function replaceChild(Readability $newNode)
+ public function replaceChild(self $newNode)
{
$this->node->parentNode->replaceChild($newNode->node, $this->node);
}
@@ -432,7 +432,7 @@ class Readability extends Element implements ReadabilityInterface
*
* @return Readability
*/
- public function createNode(Readability $originalNode, $tagName)
+ public function createNode(self $originalNode, $tagName)
{
$text = $originalNode->getTextContent();
$newNode = $originalNode->node->ownerDocument->createElement($tagName, $text);
@@ -480,7 +480,7 @@ class Readability extends Element implements ReadabilityInterface
*
* @return bool
*/
- public function hasAncestorTag(Readability $node, $tagName, $maxDepth = 3)
+ public function hasAncestorTag(self $node, $tagName, $maxDepth = 3)
{
$depth = 0;
while ($node->getParent()) {
@@ -498,7 +498,7 @@ class Readability extends Element implements ReadabilityInterface
}
/**
- * Returns the children of the current node
+ * Returns the children of the current node.
*
* @param bool $filterEmptyDOMText Filter empty DOMText nodes?
*
@@ -519,15 +519,14 @@ class Readability extends Element implements ReadabilityInterface
return $ret;
}
-
/**
- * Determines if a node has no content or it is just a bunch of dividing lines and/or whitespace
+ * Determines if a node has no content or it is just a bunch of dividing lines and/or whitespace.
*
* @return bool
*/
public function isElementWithoutContent()
{
- return ($this->node instanceof \DOMElement &&
+ return $this->node instanceof \DOMElement &&
// /\x{00A0}|\s+/u TODO to be replaced with regexps array
mb_strlen(preg_replace('/\x{00A0}|\s+/u', '', $this->node->textContent)) === 0 &&
($this->node->childNodes->length === 0 ||
@@ -544,6 +543,6 @@ class Readability extends Element implements ReadabilityInterface
return $child instanceof \DOMText;
}))
- ));
+ );
}
}