mirror of
https://github.com/j0k3r/php-readability.git
synced 2026-09-26 22:16:12 +00:00
Enable php-cs-fixer
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
/.gitignore export-ignore
|
||||
/.scrutinizer.yml export-ignore
|
||||
/.travis.yml export-ignore
|
||||
/.php_cs export-ignore
|
||||
/README.md export-ignore
|
||||
/phpunit.xml.dist export-ignore
|
||||
/tests export-ignore
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
vendor/
|
||||
coverage/
|
||||
composer.lock
|
||||
.php_cs.cache
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
return Symfony\CS\Config\Config::create()
|
||||
->setUsingCache(true)
|
||||
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
|
||||
// use default SYMFONY_LEVEL and extra fixers:
|
||||
->fixers(array(
|
||||
'concat_with_spaces',
|
||||
'ordered_use',
|
||||
'phpdoc_order',
|
||||
'strict',
|
||||
'strict_param',
|
||||
'long_array_syntax',
|
||||
))
|
||||
->finder(
|
||||
Symfony\CS\Finder\DefaultFinder::create()
|
||||
->in(__DIR__)
|
||||
->exclude(array('vendor'))
|
||||
)
|
||||
;
|
||||
@@ -10,6 +10,9 @@ php:
|
||||
- hhvm
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- php: 7.0
|
||||
env: CS_FIXER=run
|
||||
fast_finish: true
|
||||
allow_failures:
|
||||
- php: hhvm
|
||||
@@ -37,6 +40,7 @@ before_script:
|
||||
script:
|
||||
- mkdir -p build/logs
|
||||
- phpunit -v --coverage-clover build/logs/clover.xml
|
||||
- if [ "$CS_FIXER" = "run" ]; then php vendor/bin/php-cs-fixer fix --verbose --dry-run ; fi;
|
||||
|
||||
after_script:
|
||||
- php vendor/bin/coveralls -v
|
||||
|
||||
+2
-1
@@ -28,7 +28,8 @@
|
||||
"monolog/monolog": "^1.13.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"satooshi/php-coveralls": "~0.6"
|
||||
"satooshi/php-coveralls": "~0.6",
|
||||
"friendsofphp/php-cs-fixer": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Readability\\": "src/" }
|
||||
|
||||
@@ -45,14 +45,14 @@ class JSLikeHTMLElement extends \DOMElement
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
if ($name == 'innerHTML') {
|
||||
if ($name === 'innerHTML') {
|
||||
// first, empty the element
|
||||
for ($x = $this->childNodes->length - 1; $x >= 0; --$x) {
|
||||
$this->removeChild($this->childNodes->item($x));
|
||||
}
|
||||
|
||||
// $value holds our new inner HTML
|
||||
if ($value != '') {
|
||||
if ($value !== '') {
|
||||
$f = $this->ownerDocument->createDocumentFragment();
|
||||
|
||||
// appendXML() expects well-formed markup (XHTML)
|
||||
@@ -102,7 +102,7 @@ class JSLikeHTMLElement extends \DOMElement
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
if ($name == 'innerHTML') {
|
||||
if ($name === 'innerHTML') {
|
||||
$inner = '';
|
||||
|
||||
foreach ($this->childNodes as $child) {
|
||||
|
||||
+10
-10
@@ -284,7 +284,7 @@ class Readability implements LoggerAwareInterface
|
||||
|
||||
$this->html = mb_convert_encoding($this->html, 'HTML-ENTITIES', 'UTF-8');
|
||||
|
||||
if (!($this->parser == 'html5lib' && ($this->dom = \HTML5_Parser::parse($this->html)))) {
|
||||
if (!($this->parser === 'html5lib' && ($this->dom = \HTML5_Parser::parse($this->html)))) {
|
||||
libxml_use_internal_errors(true);
|
||||
|
||||
$this->dom = new \DOMDocument();
|
||||
@@ -325,7 +325,7 @@ class Readability implements LoggerAwareInterface
|
||||
$bodyElems = $this->dom->getElementsByTagName('body');
|
||||
|
||||
// WTF multiple body nodes?
|
||||
if ($this->bodyCache == null) {
|
||||
if ($this->bodyCache === null) {
|
||||
$this->bodyCache = '';
|
||||
foreach ($bodyElems as $bodyNode) {
|
||||
$this->bodyCache .= trim($bodyNode->innerHTML);
|
||||
@@ -429,7 +429,7 @@ class Readability implements LoggerAwareInterface
|
||||
}
|
||||
} elseif (mb_strlen($curTitle) > 150 || mb_strlen($curTitle) < 15) {
|
||||
$hOnes = $this->dom->getElementsByTagName('h1');
|
||||
if ($hOnes->length == 1) {
|
||||
if ($hOnes->length === 1) {
|
||||
$curTitle = $this->getInnerText($hOnes->item(0));
|
||||
}
|
||||
}
|
||||
@@ -524,7 +524,7 @@ class Readability implements LoggerAwareInterface
|
||||
$articleLink->setAttribute('style', 'color: inherit; text-decoration: none;');
|
||||
$articleLink->setAttribute('name', 'readabilityLink-' . $linkCount);
|
||||
$footnote->innerHTML = '<small><sup><a href="#readabilityLink-' . $linkCount . '" title="Jump to Link in Article">^</a></sup></small> ';
|
||||
$footnoteLink->innerHTML = ($footnoteLink->getAttribute('title') != '' ? $footnoteLink->getAttribute('title') : $linkText);
|
||||
$footnoteLink->innerHTML = ($footnoteLink->getAttribute('title') !== '' ? $footnoteLink->getAttribute('title') : $linkText);
|
||||
$footnoteLink->setAttribute('name', 'readabilityFootnoteLink-' . $linkCount);
|
||||
$footnote->appendChild($footnoteLink);
|
||||
|
||||
@@ -586,7 +586,7 @@ class Readability implements LoggerAwareInterface
|
||||
* already have a header.
|
||||
*/
|
||||
$h2s = $articleContent->getElementsByTagName('h2');
|
||||
if ($h2s->length == 1 && mb_strlen($this->getInnerText($h2s->item(0), true, true)) < 100) {
|
||||
if ($h2s->length === 1 && mb_strlen($this->getInnerText($h2s->item(0), true, true)) < 100) {
|
||||
$this->clean($articleContent, 'h2');
|
||||
}
|
||||
|
||||
@@ -971,7 +971,7 @@ class Readability implements LoggerAwareInterface
|
||||
$contentBonus = 0;
|
||||
|
||||
// Give a bonus if sibling nodes and top candidates have the same classname.
|
||||
if ($siblingNode->nodeType === XML_ELEMENT_NODE && $siblingNode->getAttribute('class') == $topCandidate->getAttribute('class') && $topCandidate->getAttribute('class') != '') {
|
||||
if ($siblingNode->nodeType === XML_ELEMENT_NODE && $siblingNode->getAttribute('class') === $topCandidate->getAttribute('class') && $topCandidate->getAttribute('class') !== '') {
|
||||
$contentBonus += ((int) $topCandidate->getAttribute('readability')) * 0.2;
|
||||
}
|
||||
|
||||
@@ -1178,7 +1178,7 @@ class Readability implements LoggerAwareInterface
|
||||
// $attributeValue = trim($element->getAttribute('class')." ".$element->getAttribute('id'));
|
||||
$attributeValue = trim($element->getAttribute($attribute));
|
||||
|
||||
if ($attributeValue != '') {
|
||||
if ($attributeValue !== '') {
|
||||
if (preg_match($this->regexps['negative'], $attributeValue)) {
|
||||
$weight -= 25;
|
||||
}
|
||||
@@ -1331,7 +1331,7 @@ class Readability implements LoggerAwareInterface
|
||||
$toRemove = false;
|
||||
|
||||
if ($this->lightClean) {
|
||||
if ($li > $p && $tag != 'ul' && $tag != 'ol') {
|
||||
if ($li > $p && $tag !== 'ul' && $tag !== 'ol') {
|
||||
$this->logger->debug(' too many <li> elements, and parent is not <ul> or <ol>');
|
||||
$toRemove = true;
|
||||
} elseif ($input > floor($p / 3)) {
|
||||
@@ -1354,7 +1354,7 @@ class Readability implements LoggerAwareInterface
|
||||
if ($img > $p) {
|
||||
$this->logger->debug(' more image elements than paragraph elements');
|
||||
$toRemove = true;
|
||||
} elseif ($li > $p && $tag != 'ul' && $tag != 'ol') {
|
||||
} elseif ($li > $p && $tag !== 'ul' && $tag !== 'ol') {
|
||||
$this->logger->debug(' too many <li> elements, and parent is not <ul> or <ol>');
|
||||
$toRemove = true;
|
||||
} elseif ($input > floor($p / 3)) {
|
||||
@@ -1369,7 +1369,7 @@ class Readability implements LoggerAwareInterface
|
||||
} elseif ($weight >= 25 && $linkDensity > 0.5) {
|
||||
$this->logger->debug(' weight above 25 but link density is ' . sprintf('%.2f', $linkDensity) . ' > 0.5');
|
||||
$toRemove = true;
|
||||
} elseif (($embedCount == 1 && $contentLength < 75) || $embedCount > 1) {
|
||||
} elseif (($embedCount === 1 && $contentLength < 75) || $embedCount > 1) {
|
||||
$this->logger->debug(' 1 embed and content length smaller than 75 chars, or more than one embed');
|
||||
$toRemove = true;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace Tests\Readability;
|
||||
|
||||
use Readability\Readability;
|
||||
use Monolog\Logger;
|
||||
use Monolog\Handler\TestHandler;
|
||||
use Monolog\Logger;
|
||||
use Readability\Readability;
|
||||
|
||||
class ReadabilityTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@@ -383,7 +383,7 @@ class ReadabilityTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* This should generate an Exception "DOMElement::setAttribute(): ID post-60 already defined"
|
||||
* This should generate an Exception "DOMElement::setAttribute(): ID post-60 already defined".
|
||||
*/
|
||||
public function testAppendIdAlreadyHere()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user