Skip to content

Commit

Permalink
Update dependencies, minimum PHP version 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fivefilters committed Apr 21, 2024
1 parent 62b04e8 commit e96b15d
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 89 deletions.
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
.PHONY: test-all

test-all: start test-7.4 test-8.0 test-8.1 stop

test-7.4:
docker-compose exec php-7.4-libxml-2.9.10 php /app/vendor/phpunit/phpunit/phpunit --configuration /app/phpunit.xml

test-8.0:
docker-compose exec php-8.0-libxml-2.9.10 php /app/vendor/phpunit/phpunit/phpunit --configuration /app/phpunit.xml
test-all: start test-8.1 test-8.2 test-8.3 stop

test-8.1:
docker-compose exec php-8.1-libxml-2.9.13 php /app/vendor/phpunit/phpunit/phpunit --configuration /app/phpunit.xml

test-8.2:
docker-compose exec php-8.2-libxml-2.9.14 php /app/vendor/phpunit/phpunit/phpunit --configuration /app/phpunit.xml

test-8.3:
docker-compose exec php-8.3-libxml-2.9.14 php /app/vendor/phpunit/phpunit/phpunit --configuration /app/phpunit.xml

start:
docker-compose up -d php-7.4-libxml-2.9.10 php-8.0-libxml-2.9.10 php-8.1-libxml-2.9.13
docker-compose up -d php-8.1-libxml-2.9.13 php-8.2-libxml-2.9.14 php-8.3-libxml-2.9.14

stop:
docker-compose stop

test-all-versions:
for php_version in 7.4 8.0 8.1; do \
for libxml_version in 2.9.10 2.9.13 2.9.14; do \
for php_version in 8.1 8.2 8.3; do \
for libxml_version in 2.9.13 2.9.14; do \
docker-compose up -d php-$$php_version-libxml-$$libxml_version; \
docker-compose exec php-$$php_version-libxml-$$libxml_version php /app/vendor/phpunit/phpunit/phpunit --configuration /app/phpunit.xml; \
done \
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
"psr-4": {"fivefilters\\Readability\\Test\\": "test"}
},
"require": {
"php": ">=7.4.0",
"php": ">=8.1",
"ext-dom": "*",
"ext-xml": "*",
"ext-mbstring": "*",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"masterminds/html5": "^2.0",
"league/uri": "~6.7.2"
"league/uri": "^7"
},
"require-dev": {
"phpunit/phpunit": "^9",
"monolog/monolog": "^2.3"
"phpunit/phpunit": "^10",
"monolog/monolog": "^3"
},
"suggest": {
"monolog/monolog": "Allow logging debug information"
Expand Down
50 changes: 13 additions & 37 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,76 +1,52 @@
version: '3'

services:
php-7.4-libxml-2.9.10: &template
php-8.1-libxml-2.9.13: &template
build:
context: ./docker/php
args:
LIBXML_VERSION: 2.9.10
PHP_VERSION: 7.4
LIBXML_VERSION: 2.9.13
PHP_VERSION: 8.1
volumes:
- ./:/app
tty: true

php-7.4-libxml-2.9.13:
<<: *template
build:
context: ./docker/php
args:
LIBXML_VERSION: 2.9.13
PHP_VERSION: 7.4

php-7.4-libxml-2.9.14:
php-8.1-libxml-2.9.14:
<<: *template
build:
context: ./docker/php
args:
LIBXML_VERSION: 2.9.14
PHP_VERSION: 7.4

php-8.0-libxml-2.9.10:
<<: *template
build:
context: ./docker/php
args:
LIBXML_VERSION: 2.9.10
PHP_VERSION: 8.0
PHP_VERSION: 8.1

php-8.0-libxml-2.9.13:
php-8.2-libxml-2.9.13:
<<: *template
build:
context: ./docker/php
args:
LIBXML_VERSION: 2.9.13
PHP_VERSION: 8.0
PHP_VERSION: 8.2

php-8.0-libxml-2.9.14:
php-8.2-libxml-2.9.14:
<<: *template
build:
context: ./docker/php
args:
LIBXML_VERSION: 2.9.14
PHP_VERSION: 8.0
PHP_VERSION: 8.2

php-8.1-libxml-2.9.10:
<<: *template
build:
context: ./docker/php
args:
LIBXML_VERSION: 2.9.10
PHP_VERSION: 8.1

php-8.1-libxml-2.9.13:
php-8.3-libxml-2.9.13:
<<: *template
build:
context: ./docker/php
args:
LIBXML_VERSION: 2.9.13
PHP_VERSION: 8.1
PHP_VERSION: 8.3

php-8.1-libxml-2.9.14:
php-8.3-libxml-2.9.14:
<<: *template
build:
context: ./docker/php
args:
LIBXML_VERSION: 2.9.14
PHP_VERSION: 8.1
PHP_VERSION: 8.3
6 changes: 3 additions & 3 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# Use build.Dockerfile to compile new versions of PHP/libxml

# For reference, default package versions for Ubuntu are:
# Ubuntu 18.04 - php 7.2, libxml2 2.9.4
# Ubuntu 20.04 - php 7.4, libxml2 2.9.10
# Ubuntu 20.10 - php 7.4, libxml2 2.9.10
# Ubuntu 21.04 - php 7.4, libxml2 2.9.10
# Ubuntu 21.10 - php 8.0, libxml2 2.9.10
# Ubuntu 22.04 - php 8.1, libxml2 2.9.13
# Ubuntu 22.10 - php 8.1, libxml2 2.9.14
# Ubuntu 23.04 - php 8.1, libxml2 2.9.14
# Ubuntu 23.10 - php 8.2, libxml2 2.9.14
# Ubuntu 24.04 - php 8.3, libxml2 2.9.14

ARG PHP_VERSION
ARG LIBXML_VERSION
Expand Down
12 changes: 6 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" stopOnFailure="false" stopOnError="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" stopOnFailure="false" stopOnError="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd">
<testsuites>
<testsuite name="Readability.php Test Suite">
<directory>./test/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
37 changes: 11 additions & 26 deletions src/Readability.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
use fivefilters\Readability\Nodes\NodeUtility;
use Psr\Log\LoggerInterface;
use Masterminds\HTML5;
use League\Uri\Http;
use League\Uri\UriResolver;
use League\Uri\BaseUri;

/**
* Class Readability.
Expand Down Expand Up @@ -409,31 +408,18 @@ private function getJSONLD(DOMDocument $dom): array
if (isset($parsed['author'])) {
if (isset($parsed['author']['name']) && is_string($parsed['author']['name'])) {
$metadata['byline'] = trim($parsed['author']['name']);
} elseif (
is_array($parsed['author']) &&
isset($parsed['author'][0]) &&
is_array($parsed['author'][0]) &&
isset($parsed['author'][0]['name']) &&
is_string($parsed['author'][0]['name'])
) {
} elseif (is_array($parsed['author']) && is_string($parsed['author'][0]['name'] ?? null)) {
$metadata['byline'] = array_filter($parsed['author'], function ($author) {
return is_array($author) && isset($author['name']) && is_string($author['name']);
return is_array($author) && is_string($author['name'] ?? null);
});
$metadata['byline'] = array_map(function ($author) {
return trim($author['name']);
}, $metadata['byline']);
$metadata['byline'] = array_map(fn($author) => trim($author['name']), $metadata['byline']);
$metadata['byline'] = implode(', ', $metadata['byline']);
}
}
if (isset($parsed['description']) && is_string($parsed['description'])) {
$metadata['excerpt'] = trim($parsed['description']);
}
if (
isset($parsed['publisher']) &&
is_array($parsed['publisher']) &&
isset($parsed['publisher']['name']) &&
is_string($parsed['publisher']['name'])
) {
if (is_array($parsed['publisher'] ?? null) && is_string($parsed['publisher']['name'] ?? null)) {
$metadata['siteName'] = trim($parsed['publisher']['name']);
}
return $metadata;
Expand Down Expand Up @@ -527,7 +513,7 @@ private function getMetadata()
if (isset($this->jsonld['byline'])) {
$this->setAuthor($this->jsonld['byline']);
} else {
$this->setAuthor(isset($values[$key]) ? $values[$key] : null);
$this->setAuthor($values[$key] ?? null);
}

// get description
Expand All @@ -544,7 +530,7 @@ private function getMetadata()
if (isset($this->jsonld['excerpt'])) {
$this->setExcerpt($this->jsonld['excerpt']);
} else {
$this->setExcerpt(isset($values[$key]) ? $values[$key] : null);
$this->setExcerpt($values[$key] ?? null);
}

// get main image
Expand All @@ -554,7 +540,7 @@ private function getMetadata()
'twitter:image'
], array_keys($values)));

$this->setImage(isset($values[$key]) ? $values[$key] : null);
$this->setImage($values[$key] ?? null);

$key = current(array_intersect([
'og:site_name'
Expand All @@ -563,7 +549,7 @@ private function getMetadata()
if (isset($this->jsonld['siteName'])) {
$this->setSiteName($this->jsonld['siteName']);
} else {
$this->setSiteName(isset($values[$key]) ? $values[$key] : null);
$this->setSiteName($values[$key] ?? null);
}

// in many sites the meta value is escaped with HTML entities,
Expand Down Expand Up @@ -816,9 +802,8 @@ private function toAbsoluteURI($uri)
// return $pathBase . substr($uri, 2);
//}

$baseUri = Http::createFromString($pathBase);
$relativeUri = Http::createFromString($uri);
return (string)UriResolver::resolve($relativeUri, $baseUri);
$baseUri = BaseUri::from($pathBase);
return (string) $baseUri->resolve($uri);

// Standard relative URI; add entire path. pathBase already includes a
// trailing "/".
Expand Down
4 changes: 2 additions & 2 deletions test/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ private function doEqualsAsserts(Configuration $config, array $options)
/**
* @return array
*/
public function getParams()
public static function getParams(): array
{
return [[
'All current parameters' => [
'params' => [
'maxTopCandidates' => 3,
'wordThreshold' => 500,
'charThreshold' => 500,
Expand Down
2 changes: 1 addition & 1 deletion test/ReadabilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function testHTMLParserParsesImages(TestPage $testPage)
*
* @return \Generator
*/
public function getSamplePages()
public static function getSamplePages()
{
$path = pathinfo(__FILE__, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . 'test-pages';
$testPages = scandir($path);
Expand Down

0 comments on commit e96b15d

Please sign in to comment.