Skip to content

Commit

Permalink
[+]: update "symfony/css-selector"
Browse files Browse the repository at this point in the history
-> fix phpstan reported errors
  • Loading branch information
voku committed Feb 23, 2020
1 parent b0ce5bf commit 9b00eb4
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 26 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ php:
- 7.1
- 7.2
- 7.3
- 7.4

before_script:
- wget https://scrutinizer-ci.com/ocular.phar
- travis_retry composer self-update
- travis_retry composer require satooshi/php-coveralls
- travis_retry composer require phpstan/phpstan-shim
- if [ "$(phpenv version-name)" == 7.3 ]; then travis_retry composer require phpstan/phpstan; fi
- travis_retry composer install --no-interaction --prefer-source
- composer dump-autoload -o

script:
- mkdir -p build/logs
- php vendor/bin/phpunit -c phpunit.xml
- php vendor/bin/phpstan analyse --level=7 --configuration=phpstan.neon src
- if [ "$(phpenv version-name)" == 7.3 ]; then php vendor/bin/phpstan analyse; fi

after_script:
- php vendor/bin/coveralls -v
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
],
"require": {
"php": ">=7.0.0",
"symfony/css-selector": "~3.0 || ~4.0",
"voku/simple_html_dom": "~4.5",
"symfony/css-selector": "~3.0 || ~4.0 || ~5.0",
"voku/simple_html_dom": "~4.7",
"ext-dom": "*"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion phpcs.php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ return PhpCsFixer\Config::create()
'no_unset_on_property' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_useless_return' => false, // allow void
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'non_printable_character' => true,
Expand Down
12 changes: 6 additions & 6 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
parameters:
level: max
reportUnmatchedIgnoredErrors: false
excludes_analyse:
- %rootDir%/vendor/*
- %rootDir%/tests/*
autoload_files:
- %rootDir%/vendor/autoload.php
checkGenericClassInNonGenericObjectType: true
checkMissingIterableValueType: false
paths:
- %currentWorkingDirectory%/src/
ignoreErrors:
- '#Binary operation "-" between voku\\CssToInlineStyles\\Specificity#'
- '#Unsafe usage of new static#'
3 changes: 0 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src/</directory>
</whitelist>
<blacklist>
<directory suffix=".php">./vendor</directory>
</blacklist>
</filter>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
Expand Down
23 changes: 15 additions & 8 deletions src/CssToInlineStyles.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,12 @@ public function setUseInlineStylesBlock(bool $on = true): self
* Remove id and class attributes.
*
* @param \DOMXPath $xPath the DOMXPath for the entire document
*
* @return void
*/
private function cleanupHTML(\DOMXPath $xPath)
{
/** @var \DOMAttr[]|\DOMNodeList|false $nodes */
/** @var \DOMAttr[]|\DOMNodeList<\DOMAttr>|false $nodes */
$nodes = $xPath->query('//@class | //@id');
if ($nodes !== false) {
foreach ($nodes as $node) {
Expand Down Expand Up @@ -546,7 +548,7 @@ private function createXPath(\DOMDocument $document, array $cssRules): \DOMXPath
}

// search elements
/** @var \DOMElement[]|\DOMNodeList|false $elements */
/** @var \DOMElement[]|\DOMNodeList<\DOMElement>|false $elements */
$elements = $xPath->query($query);

// validate elements
Expand All @@ -556,8 +558,6 @@ private function createXPath(\DOMDocument $document, array $cssRules): \DOMXPath

// loop found elements
foreach ($elements as $element) {

/** @var \DOMElement */
if (
$ruleSelector === '*'
&&
Expand Down Expand Up @@ -799,10 +799,13 @@ private function processCSSProperties($propertyString): array
*
* INFO: Lower specificity will be sorted to the beginning of the array.
*
* @param Specificity[] $e1 the first element
* @param Specificity[] $e2 the second element
* @param array $e1 the first element
* @param array $e2 the second element
*
* @return int
*
* @psalm-param array<specificity: Specificity, order: int> $e1
* @psalm-param array<specificity: Specificity, order: int> $e2
*/
private static function sortOnSpecificity(array $e1, array $e2): int
{
Expand Down Expand Up @@ -888,11 +891,13 @@ private function splitStyleIntoChunks(array $definedProperties): array
* Strip style tags into the generated HTML.
*
* @param \DOMXPath $xPath the DOMXPath for the entire document
*
* @return void
*/
private function stripOriginalStyleTags(\DOMXPath $xPath)
{
// get all style tags
/** @var \DOMElement[]|\DOMNodeList|false $nodes */
/** @var \DOMElement[]|\DOMNodeList<\DOMElement>|false $nodes */
$nodes = $xPath->query('descendant-or-self::style');
if ($nodes !== false) {
foreach ($nodes as $node) {
Expand All @@ -908,7 +913,9 @@ private function stripOriginalStyleTags(\DOMXPath $xPath)
$node->nodeValue = \implode("\n", $mqs[0]);
} else {
// remove the entire style tag
$node->parentNode->removeChild($node);
if ($node->parentNode !== null) {
$node->parentNode->removeChild($node);
}
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/Specificity.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public function __construct($a = 0, $b = 0, $c = 0)
* @param int $a The number of ID selectors in the selector
* @param int $b The number of class selectors, attributes selectors, and pseudo-classes in the selector
* @param int $c The number of type selectors and pseudo-elements in the selector
*
* @return void
*/
public function increase($a, $b, $c)
{
Expand Down Expand Up @@ -110,10 +112,10 @@ public static function fromSelector(string $selector)
)";

return new static(
\preg_match_all("/{$pattern_a}/ix", $selector, $matches),
\preg_match_all("/{$pattern_b}/ix", $selector, $matches),
\preg_match_all("/{$pattern_c}/ix", $selector, $matches)
);
(int)\preg_match_all("/{$pattern_a}/ix", $selector, $matches),
(int)\preg_match_all("/{$pattern_b}/ix", $selector, $matches),
(int)\preg_match_all("/{$pattern_c}/ix", $selector, $matches)
);
}

/**
Expand Down

0 comments on commit 9b00eb4

Please sign in to comment.