Skip to content

Commit 2912276

Browse files
authored
Merge pull request #89 from jtojnar/php74
Require PHP 7.4
2 parents f28191a + 89d3b74 commit 2912276

File tree

7 files changed

+43
-32
lines changed

7 files changed

+43
-32
lines changed

.github/workflows/coding-standards.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
matrix:
1818
php:
19-
- "7.2"
19+
- "7.4"
2020

2121
steps:
2222
- name: "Checkout"

.github/workflows/continuous-integration.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ jobs:
1919
strategy:
2020
matrix:
2121
php:
22-
- "7.2"
23-
- "7.3"
2422
- "7.4"
2523
- "8.0"
2624
- "8.1"
@@ -65,7 +63,7 @@ jobs:
6563
strategy:
6664
matrix:
6765
php:
68-
- "7.4"
66+
- "8.0"
6967

7068
steps:
7169
- name: "Checkout"
@@ -116,7 +114,7 @@ jobs:
116114
strategy:
117115
matrix:
118116
php:
119-
- "7.2"
117+
- "7.4"
120118

121119
steps:
122120
- name: "Checkout"

.php-cs-fixer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
'strict_comparison' => true,
2727
'strict_param' => true,
2828
'concat_space' => ['spacing' => 'one'],
29+
// Pulled in by @Symfony:risky but we still support PHP 7.4
30+
'modernize_strpos' => false,
31+
// Pulled in by @Symfony, we cannot add property types until we bump PHP to ≥ 7.4
32+
'no_null_property_initialization' => false,
2933
])
3034
->setFinder($finder)
3135
;

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"role": "Developer (original JS version)"
2525
}],
2626
"require": {
27-
"php": ">=7.2.0",
27+
"php": ">=7.4.0",
2828
"ext-mbstring": "*",
2929
"psr/log": "^1.0.1 || ^2.0 || ^3.0",
3030
"masterminds/html5": "^2.7"

rector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424
// Define what rule sets will be applied
2525
$rectorConfig->sets([
26-
LevelSetList::UP_TO_PHP_72,
26+
LevelSetList::UP_TO_PHP_74,
2727
]);
2828

2929
// is your PHP version different from the one your refactor to?
30-
$rectorConfig->phpVersion(PhpVersion::PHP_72);
30+
$rectorConfig->phpVersion(PhpVersion::PHP_74);
3131
};

src/Readability.php

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class Readability implements LoggerAwareInterface
142142
* @param string $parser Which parser to use for turning raw HTML into a DOMDocument
143143
* @param bool $useTidy Use tidy
144144
*/
145-
public function __construct(string $html, string $url = null, string $parser = 'libxml', bool $useTidy = true)
145+
public function __construct(string $html, ?string $url = null, string $parser = 'libxml', bool $useTidy = true)
146146
{
147147
$this->url = $url;
148148
$this->html = $html;
@@ -739,15 +739,15 @@ public function flagIsActive(int $flag): bool
739739
*/
740740
public function addFlag(int $flag): void
741741
{
742-
$this->flags = $this->flags | $flag;
742+
$this->flags |= $flag;
743743
}
744744

745745
/**
746746
* Remove a flag.
747747
*/
748748
public function removeFlag(int $flag): void
749749
{
750-
$this->flags = $this->flags & ~$flag;
750+
$this->flags &= ~$flag;
751751
}
752752

753753
/**
@@ -893,11 +893,9 @@ protected function initializeNode(\DOMElement $node): void
893893
* Using a variety of metrics (content score, classname, element types), find the content that is
894894
* most likely to be the stuff a user wants to read. Then return it wrapped up in a div.
895895
*
896-
* @param \DOMElement $page
897-
*
898896
* @return \DOMElement|false
899897
*/
900-
protected function grabArticle(\DOMElement $page = null)
898+
protected function grabArticle(?\DOMElement $page = null)
901899
{
902900
if (!$page) {
903901
$page = $this->dom;
@@ -933,9 +931,9 @@ protected function grabArticle(\DOMElement $page = null)
933931
// Remove unlikely candidates
934932
$unlikelyMatchString = $node->getAttribute('class') . ' ' . $node->getAttribute('id') . ' ' . $node->getAttribute('style');
935933

936-
if (mb_strlen($unlikelyMatchString) > 3 && // don't process "empty" strings
937-
preg_match($this->regexps['unlikelyCandidates'], $unlikelyMatchString) &&
938-
!preg_match($this->regexps['okMaybeItsACandidate'], $unlikelyMatchString)
934+
if (mb_strlen($unlikelyMatchString) > 3 // don't process "empty" strings
935+
&& preg_match($this->regexps['unlikelyCandidates'], $unlikelyMatchString)
936+
&& !preg_match($this->regexps['okMaybeItsACandidate'], $unlikelyMatchString)
939937
) {
940938
$this->logger->debug('Removing unlikely candidate (using conf) ' . $node->getNodePath() . ' by "' . $unlikelyMatchString . '"');
941939
$node->parentNode->removeChild($node);
@@ -1120,9 +1118,11 @@ protected function grabArticle(\DOMElement $page = null)
11201118
}
11211119
}
11221120

1123-
$topCandidates = array_filter($topCandidates, function ($v, $idx) {
1124-
return 0 === $idx || null !== $v;
1125-
}, \ARRAY_FILTER_USE_BOTH);
1121+
$topCandidates = array_filter(
1122+
$topCandidates,
1123+
fn ($v, $idx) => 0 === $idx || null !== $v,
1124+
\ARRAY_FILTER_USE_BOTH
1125+
);
11261126
$topCandidate = $topCandidates[0];
11271127

11281128
/*
@@ -1442,7 +1442,7 @@ private function loadHtml(): void
14421442
libxml_use_internal_errors(false);
14431443
}
14441444

1445-
$this->dom->registerNodeClass(\DOMElement::class, \Readability\JSLikeHTMLElement::class);
1445+
$this->dom->registerNodeClass(\DOMElement::class, JSLikeHTMLElement::class);
14461446
}
14471447

14481448
private function getAncestors(\DOMElement $node, int $maxDepth = 0): array
@@ -1464,9 +1464,17 @@ private function isPhrasingContent($node): bool
14641464
{
14651465
return \XML_TEXT_NODE === $node->nodeType
14661466
|| \in_array(strtoupper($node->nodeName), $this->phrasingElements, true)
1467-
|| (\in_array(strtoupper($node->nodeName), ['A', 'DEL', 'INS'], true) && !\in_array(false, array_map(function ($c) {
1468-
return $this->isPhrasingContent($c);
1469-
}, iterator_to_array($node->childNodes)), true));
1467+
|| (
1468+
\in_array(strtoupper($node->nodeName), ['A', 'DEL', 'INS'], true)
1469+
&& !\in_array(
1470+
false,
1471+
array_map(
1472+
fn ($c) => $this->isPhrasingContent($c),
1473+
iterator_to_array($node->childNodes)
1474+
),
1475+
true
1476+
)
1477+
);
14701478
}
14711479

14721480
private function hasSingleTagInsideElement(\DOMElement $node, string $tag): bool
@@ -1475,10 +1483,10 @@ private function hasSingleTagInsideElement(\DOMElement $node, string $tag): bool
14751483
return false;
14761484
}
14771485

1478-
$a = array_filter(iterator_to_array($node->childNodes), function ($childNode) {
1479-
return $childNode instanceof \DOMText &&
1480-
preg_match($this->regexps['hasContent'], $this->getInnerText($childNode));
1481-
});
1486+
$a = array_filter(
1487+
iterator_to_array($node->childNodes),
1488+
fn ($childNode) => $childNode instanceof \DOMText && preg_match($this->regexps['hasContent'], $this->getInnerText($childNode))
1489+
);
14821490

14831491
return 0 === \count($a);
14841492
}
@@ -1491,9 +1499,10 @@ private function hasSingleTagInsideElement(\DOMElement $node, string $tag): bool
14911499
*/
14921500
private function isNodeVisible(\DOMElement $node): bool
14931501
{
1494-
return !($node->hasAttribute('style')
1495-
&& preg_match($this->regexps['isNotVisible'], $node->getAttribute('style'))
1502+
return !(
1503+
$node->hasAttribute('style')
1504+
&& preg_match($this->regexps['isNotVisible'], $node->getAttribute('style'))
14961505
)
1497-
&& !$node->hasAttribute('hidden');
1506+
&& !$node->hasAttribute('hidden');
14981507
}
14991508
}

tests/ReadabilityTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ public function testVisibleNode(string $content, bool $shouldBeVisible): void
550550
}
551551
}
552552

553-
private function getReadability(string $html, string $url = null, string $parser = 'libxml', bool $useTidy = true): Readability
553+
private function getReadability(string $html, ?string $url = null, string $parser = 'libxml', bool $useTidy = true): Readability
554554
{
555555
$readability = new Readability($html, $url, $parser, $useTidy);
556556

0 commit comments

Comments
 (0)