Skip to content

Commit

Permalink
Apply PHP-CS-Fixer fixes
Browse files Browse the repository at this point in the history
PHP-CS-Fixer 3.17.0 enables new rules, let’s apply them to code.
  • Loading branch information
jtojnar committed May 22, 2023
1 parent a301ffe commit 22ac9ca
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 22 deletions.
8 changes: 8 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@
'method_argument_space' => false,
'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,
// Enabled by @Symfony but is inconsistent.
'nullable_type_declaration_for_default_null_value' => [
'use_nullable_type_declaration' => true,
],
'ordered_class_elements' => true,
'ordered_imports' => true,
'php_unit_strict' => true,
Expand Down
18 changes: 9 additions & 9 deletions src/Extractor/ContentExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ContentExtractor
* json_ld_ignore_types?: string[],
* } $config
*/
public function __construct(array $config = [], LoggerInterface $logger = null, ConfigBuilder $configBuilder = null)
public function __construct(array $config = [], ?LoggerInterface $logger = null, ?ConfigBuilder $configBuilder = null)
{
$this->config = new ContentExtractorConfig($config);

Expand Down Expand Up @@ -139,7 +139,7 @@ public function buildSiteConfig(UriInterface $url, string $html = '', bool $addT
*
* @return bool true on success, false on failure
*/
public function process(string $html, UriInterface $url, SiteConfig $siteConfig = null, bool $smartTidy = true): bool
public function process(string $html, UriInterface $url, ?SiteConfig $siteConfig = null, bool $smartTidy = true): bool
{
$this->reset();

Expand Down Expand Up @@ -771,7 +771,7 @@ private function hasElements($elems = false): bool
* @param \DOMNodeList<\DOMNode>|false $elems Not force typed because it can also be false
* @param string $logMessage
*/
private function removeElements($elems = false, string $logMessage = null): void
private function removeElements($elems = false, ?string $logMessage = null): void
{
if (false === $elems || false === $this->hasElements($elems)) {
return;
Expand Down Expand Up @@ -800,7 +800,7 @@ private function removeElements($elems = false, string $logMessage = null): void
* @param \DOMNodeList<\DOMNode>|false $elems
* @param string $logMessage
*/
private function wrapElements($elems = false, string $tag = 'div', string $logMessage = null): void
private function wrapElements($elems = false, string $tag = 'div', ?string $logMessage = null): void
{
if (false === $elems || false === $this->hasElements($elems)) {
return;
Expand Down Expand Up @@ -841,7 +841,7 @@ private function wrapElements($elems = false, string $tag = 'div', string $logMe
*
* @return bool Telling if we have to detect entity again or not
*/
private function extractEntityFromQuery(string $entity, bool $detectEntity, string $xpathExpression, \DOMNode $node, string $logMessage, callable $returnCallback = null): bool
private function extractEntityFromQuery(string $entity, bool $detectEntity, string $xpathExpression, \DOMNode $node, string $logMessage, ?callable $returnCallback = null): bool
{
if (false === $detectEntity) {
return false;
Expand Down Expand Up @@ -889,7 +889,7 @@ private function extractEntityFromQuery(string $entity, bool $detectEntity, stri
*
* @return bool Telling if we have to detect title again or not
*/
private function extractTitle(bool $detectTitle, string $cssClass, \DOMNode $node = null, string $logMessage): bool
private function extractTitle(bool $detectTitle, string $cssClass, ?\DOMNode $node = null, string $logMessage): bool
{
if (null === $node) {
return true;
Expand All @@ -913,7 +913,7 @@ private function extractTitle(bool $detectTitle, string $cssClass, \DOMNode $nod
*
* @return bool Telling if we have to detect date again or not
*/
private function extractDate(bool $detectDate, string $cssClass, \DOMNode $node = null, string $logMessage): bool
private function extractDate(bool $detectDate, string $cssClass, ?\DOMNode $node = null, string $logMessage): bool
{
if (null === $node) {
return true;
Expand All @@ -936,7 +936,7 @@ private function extractDate(bool $detectDate, string $cssClass, \DOMNode $node
*
* @return bool Telling if we have to detect author again or not
*/
private function extractAuthor(bool $detectAuthor, \DOMNode $node = null): bool
private function extractAuthor(bool $detectAuthor, ?\DOMNode $node = null): bool
{
if (false === $detectAuthor || !$this->xpath) {
return false;
Expand Down Expand Up @@ -984,7 +984,7 @@ private function extractAuthor(bool $detectAuthor, \DOMNode $node = null): bool
*
* @return bool Telling if we have to detect body again or not
*/
private function extractBody(bool $detectBody, string $xpathExpression, \DOMNode $node = null, string $type): bool
private function extractBody(bool $detectBody, string $xpathExpression, ?\DOMNode $node = null, string $type): bool
{
if (false === $detectBody || !$this->xpath) {
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
/**
* @param ClientInterface $client Http client
*/
public function __construct(ClientInterface $client, array $config = [], LoggerInterface $logger = null, ContentExtractor $extractor = null)
public function __construct(ClientInterface $client, array $config = [], ?LoggerInterface $logger = null, ?ContentExtractor $extractor = null)
{
$this->config = new HttpClientConfig($config);

Expand Down
2 changes: 1 addition & 1 deletion src/Graby.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Graby

private ?string $prefetchedContent = null;

public function __construct(array $config = [], ?ClientInterface $client = null, ConfigBuilder $configBuilder = null)
public function __construct(array $config = [], ?ClientInterface $client = null, ?ConfigBuilder $configBuilder = null)
{
$this->config = new GrabyConfig($config);

Expand Down
3 changes: 0 additions & 3 deletions src/HttpClient/Plugin/CookiePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ public function __construct(CookieJar $cookieJar)
$this->cookieJar = $cookieJar;
}

/**
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
{
$cookies = [];
Expand Down
2 changes: 1 addition & 1 deletion src/OptionsResolver/ArrayStringOptionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
trait ArrayStringOptionsTrait
{
public function validateArray(array $array, string $option, string $key = null): void
public function validateArray(array $array, string $option, ?string $key = null): void
{
if (null === $key) {
foreach ($array as $arrayKey => $arrayValue) {
Expand Down
12 changes: 6 additions & 6 deletions src/SiteConfig/ConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ConfigBuilder
'div',
];

public function __construct(array $config = [], LoggerInterface $logger = null)
public function __construct(array $config = [], ?LoggerInterface $logger = null)
{
$this->config = new ConfigBuilderConfig($config);

Expand Down Expand Up @@ -335,23 +335,23 @@ public function parseLines(array $lines): SiteConfig
$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 (str_ends_with($command, ')') && 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 (str_ends_with($command, ')') && 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 (str_ends_with($command, ')') && 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
2 changes: 1 addition & 1 deletion tests/Extractor/ContentExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,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::CONTENT_EXTRACTOR_CONFIG);

Expand Down

0 comments on commit 22ac9ca

Please sign in to comment.