Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.x] Fix CI #363

Merged
merged 7 commits into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
coverage: "none"
php-version: "${{ matrix.php }}"
tools: cs2pr, composer:v2
ini-values: "date.timezone=Europe/Paris"
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ jobs:
coverage: "none"
tools: composer:v2
extensions: tidy
ini-values: "date.timezone=Europe/Paris"
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down Expand Up @@ -78,7 +77,6 @@ jobs:
coverage: "pcov"
tools: composer:v2
extensions: tidy
ini-values: "date.timezone=Europe/Paris"
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down Expand Up @@ -124,7 +122,6 @@ jobs:
coverage: "none"
tools: composer:v2
extensions: tidy
ini-values: "date.timezone=Europe/Paris"
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down Expand Up @@ -161,7 +158,6 @@ jobs:
coverage: "none"
tools: composer:v2
extensions: tidy
ini-values: "date.timezone=Europe/Paris"
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -171,7 +167,7 @@ jobs:
- name: "Setup adapter: Guzzle 5"
run: |
composer remove guzzlehttp/guzzle php-http/guzzle6-adapter --dev -n
composer require php-http/guzzle5-adapter --dev -n
composer require php-http/guzzle5-adapter --dev -n --with-all-dependencies

- name: "Setup logs"
run: "mkdir -p build/logs"
Expand Down Expand Up @@ -241,7 +237,6 @@ jobs:
coverage: "none"
tools: composer:v2
extensions: tidy
ini-values: "date.timezone=Europe/Paris"
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down Expand Up @@ -281,7 +276,6 @@ jobs:
coverage: "none"
tools: composer:v1
extensions: tidy
ini-values: "date.timezone=Europe/Paris"
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
4 changes: 4 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
'@Symfony:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'combine_consecutive_unsets' => true,
// Enabled by @Symfony:risky but requires PHP 8.
'get_class_to_class_keyword' => false,
'heredoc_to_nowdoc' => true,
'no_extra_blank_lines' => ['tokens' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block']],
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
// Enabled by Symfony and changes properties without type hints but we cannot use those yet because they require PHP 8.
'no_null_property_initialization' => false,
'ordered_class_elements' => true,
'ordered_imports' => true,
'php_unit_strict' => true,
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
"Tests\\Graby\\": "tests/"
}
},
"scripts": {
"fix": "php-cs-fixer fix --verbose --diff",
"phpstan": "phpstan analyse --memory-limit 512M",
"test": "simple-phpunit -v"
},
"config": {
"sort-packages": true,
"allow-plugins": {
Expand Down
2 changes: 2 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[direct]=0" />

<ini name="date.timezone" value="Europe/Paris"/>
</php>

<!-- <logging>
Expand Down
12 changes: 6 additions & 6 deletions src/Extractor/ContentExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ContentExtractor
/**
* @param array $config
*/
public function __construct($config = [], LoggerInterface $logger = null, ConfigBuilder $configBuilder = null)
public function __construct($config = [], ?LoggerInterface $logger = null, ?ConfigBuilder $configBuilder = null)
{
$resolver = new OptionsResolver();
$resolver->setDefaults([
Expand Down Expand Up @@ -166,7 +166,7 @@ public function buildSiteConfig($url, $html = '', $addToCache = true)
*
* @return bool true on success, false on failure
*/
public function process($html, $url, SiteConfig $siteConfig = null, $smartTidy = true)
public function process($html, $url, ?SiteConfig $siteConfig = null, $smartTidy = true)
{
$this->reset();

Expand Down Expand Up @@ -888,7 +888,7 @@ private function extractEntityFromQuery($entity, $detectEntity, $xpathExpression
*
* @return bool Telling if we have to detect title again or not
*/
private function extractTitle($detectTitle, $cssClass, \DOMNode $node = null, $logMessage)
private function extractTitle($detectTitle, $cssClass, ?\DOMNode $node, $logMessage)
{
if (null === $node) {
return true;
Expand All @@ -913,7 +913,7 @@ private function extractTitle($detectTitle, $cssClass, \DOMNode $node = null, $l
*
* @return bool Telling if we have to detect date again or not
*/
private function extractDate($detectDate, $cssClass, \DOMNode $node = null, $logMessage)
private function extractDate($detectDate, $cssClass, ?\DOMNode $node, $logMessage)
{
if (null === $node) {
return true;
Expand All @@ -936,7 +936,7 @@ private function extractDate($detectDate, $cssClass, \DOMNode $node = null, $log
*
* @return bool Telling if we have to detect author again or not
*/
private function extractAuthor($detectAuthor, \DOMNode $node = null)
private function extractAuthor($detectAuthor, ?\DOMNode $node)
{
if (false === $detectAuthor) {
return false;
Expand Down Expand Up @@ -983,7 +983,7 @@ private function extractAuthor($detectAuthor, \DOMNode $node = null)
*
* @return bool Telling if we have to detect body again or not
*/
private function extractBody($detectBody, $xpathExpression, \DOMNode $node = null, $type)
private function extractBody($detectBody, $xpathExpression, ?\DOMNode $node, $type)
{
if (false === $detectBody) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Extractor/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class HttpClient
*/
private $responseHistory;

public function __construct(ClientInterface $client, $config = [], LoggerInterface $logger = null)
public function __construct(ClientInterface $client, $config = [], ?LoggerInterface $logger = null)
{
$resolver = new OptionsResolver();
$resolver->setDefaults([
Expand Down
14 changes: 7 additions & 7 deletions src/Graby.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Graby
private $imgNoReferrer = false;
private $prefetchedContent;

public function __construct($config = [], ClientInterface $client = null, ConfigBuilder $configBuilder = null)
public function __construct($config = [], ?ClientInterface $client = null, ?ConfigBuilder $configBuilder = null)
{
$resolver = new OptionsResolver();
$resolver->setDefaults([
Expand Down Expand Up @@ -150,7 +150,7 @@ public function reloadConfigFiles()
public function getConfig($key)
{
if (!isset($this->config[$key])) {
throw new \Exception(sprintf('No config found for key: "%s"', $key));
throw new \Exception(\sprintf('No config found for key: "%s"', $key));
}

return $this->config[$key];
Expand Down Expand Up @@ -307,7 +307,7 @@ private function doFetchContent($url)
$effectiveUrl = $response['effective_url'];
$effectiveUrl = str_replace(' ', '%20', $effectiveUrl);
if (!$this->isUrlAllowed($effectiveUrl)) {
throw new \Exception(sprintf('Url "%s" is not allowed to be parsed.', $effectiveUrl));
throw new \Exception(\sprintf('Url "%s" is not allowed to be parsed.', $effectiveUrl));
}

// check if action defined for returned Content-Type, like image, pdf, audio or video
Expand Down Expand Up @@ -511,17 +511,17 @@ private function validateUrl($url)
$url = (string) $uri;

if (false === filter_var($url, \FILTER_VALIDATE_URL)) {
throw new \InvalidArgumentException(sprintf('Url "%s" is not valid.', $url));
throw new \InvalidArgumentException(\sprintf('Url "%s" is not valid.', $url));
}

$url = filter_var($url, \FILTER_SANITIZE_URL);

if (false === $url) {
throw new \InvalidArgumentException(sprintf('Sanitizing url "%s" failed.', $url));
throw new \InvalidArgumentException(\sprintf('Sanitizing url "%s" failed.', $url));
}

if (false === $this->isUrlAllowed($url)) {
throw new \InvalidArgumentException(sprintf('Url "%s" is not allowed to be parsed.', $url));
throw new \InvalidArgumentException(\sprintf('Url "%s" is not allowed to be parsed.', $url));
}

return $url;
Expand Down Expand Up @@ -621,7 +621,7 @@ private function handleMimeAction($mimeInfo, $effectiveUrl, $response = [])
];

if ('exclude' === $mimeInfo['action']) {
throw new \Exception(sprintf('This is url "%s" is blocked by mime action.', $effectiveUrl));
throw new \Exception(\sprintf('This is url "%s" is blocked by mime action.', $effectiveUrl));
}

$infos['html'] = '<a href="' . $effectiveUrl . '">Download ' . $mimeInfo['name'] . '</a>';
Expand Down
4 changes: 2 additions & 2 deletions src/HttpClient/Plugin/CookiePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
continue;
}

$cookies[] = sprintf('%s=%s', $cookie->getName(), $cookie->getValue());
$cookies[] = \sprintf('%s=%s', $cookie->getName(), $cookie->getValue());
}

if (!empty($cookies)) {
Expand Down Expand Up @@ -114,7 +114,7 @@ private function createCookie(RequestInterface $request, string $setCookieHeader
try {
$expires = CookieUtil::parseDate((string) $value);
} catch (UnexpectedValueException $e) {
throw new TransferException(sprintf('Cookie header `%s` expires value `%s` could not be converted to date', $name, $value), 0, $e);
throw new TransferException(\sprintf('Cookie header `%s` expires value `%s` could not be converted to date', $name, $value), 0, $e);
}

break;
Expand Down
12 changes: 6 additions & 6 deletions src/SiteConfig/ConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ConfigBuilder
/**
* @param array $config
*/
public function __construct($config = [], LoggerInterface $logger = null)
public function __construct($config = [], ?LoggerInterface $logger = null)
{
$resolver = new OptionsResolver();
$resolver->setDefaults([
Expand Down Expand Up @@ -385,23 +385,23 @@ public function parseLines(array $lines)
$command = 'strip';
}

// check for commands where we accept multiple statements
if (\in_array($command, ['title', 'body', 'strip', 'strip_id_or_class', 'strip_image_src', 'single_page_link', 'next_page_link', 'test_url', 'find_string', 'replace_string', 'login_extra_fields', 'native_ad_clue', 'date', 'author'], true)) {
// check for commands where we accept multiple statements
$config->$command[] = $val;
// check for single statement commands that evaluate to true or false
} elseif (\in_array($command, ['tidy', 'prune', 'autodetect_on_failure', 'requires_login', 'skip_json_ld'], true)) {
// check for single statement commands that evaluate to true or false
$config->$command = ('yes' === $val || 'true' === $val);
// check for single statement commands stored as strings
} elseif (\in_array($command, ['parser', 'login_username_field', 'login_password_field', 'not_logged_in_xpath', 'login_uri', 'src_lazy_load_attr'], true)) {
// check for single statement commands stored as strings
$config->$command = $val;
// check for replace_string(find): replace
} elseif ((')' === substr($command, -1)) && preg_match('!^([a-z0-9_]+)\((.*?)\)$!i', $command, $match) && 'replace_string' === $match[1]) {
// check for replace_string(find): replace
$config->find_string[] = $match[2];
$config->replace_string[] = $val;
} elseif ((')' === substr($command, -1)) && preg_match('!^([a-z0-9_]+)\(([a-z0-9_-]+)\)$!i', $command, $match) && 'http_header' === $match[1] && \in_array(strtolower($match[2]), $this->acceptedHeaders, true)) {
$config->http_header[strtolower(trim($match[2]))] = $val;
// special treatment for if_page_contains
} elseif (\in_array($command, ['if_page_contains'], true)) {
// special treatment for if_page_contains
$this->handleIfPageContainsCondition($config, $val);
} elseif ((')' === substr($command, -1)) && preg_match('!([a-z0-9_]+)\(([a-z]+)\)$!i', $command, $match) && 'wrap_in' === $match[1] && \in_array(strtolower($match[2]), $this->acceptedWrapInTags, true)) {
$config->wrap_in[strtolower(trim($match[2]))] = $val;
Expand Down
14 changes: 7 additions & 7 deletions tests/Extractor/ContentExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public function dataForStripIdOrClass(): array
/**
* @dataProvider dataForStripIdOrClass
*/
public function testApplyStripIdOrClass(string $pattern, string $html, ?string $removedContent, string $matchContent = null): void
public function testApplyStripIdOrClass(string $pattern, string $html, ?string $removedContent, ?string $matchContent = null): void
{
$contentExtractor = new ContentExtractor(self::$contentExtractorConfig);

Expand Down Expand Up @@ -482,14 +482,14 @@ public function dataForStripAttr(): array
{
return [
[['//*/@class'], '<html><body><div class="hello world"><i class="class">bar</i>class="foo"' . str_repeat('this is the best part of the show', 10) . ' <a class="hc" href="void">link</a></div></body></html>', [
'removedContent' => ['class="class"', 'class="hello world"', 'class="hc"'],
'keptContent' => ['class="foo"', '<a href="void"', '<em>bar'],
],
'removedContent' => ['class="class"', 'class="hello world"', 'class="hc"'],
'keptContent' => ['class="foo"', '<a href="void"', '<em>bar'],
],
],
[['//img/@class', '//p/@class'], '<html><body><img class="bar-class" src="void" /><a class="hello" href="void">link</a> <p class="yes">' . str_repeat('this is the best part of the show', 10) . '</p></body></html>', [
'removedContent' => ['class="bar-class"', 'class="yes"'],
'keptContent' => ['class="hello"'],
],
'removedContent' => ['class="bar-class"', 'class="yes"'],
'keptContent' => ['class="hello"'],
],
],
];
}
Expand Down
Loading
Loading