Skip to content

Commit

Permalink
[TASK] Upgrade to PHPStan 2.x and Rector 2.x (#1376)
Browse files Browse the repository at this point in the history
We'll allow `assertInstanceOf` checks in the tests again in a
later change.
  • Loading branch information
oliverklee authored Dec 12, 2024
1 parent 829cf37 commit e6c33d9
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ updates:
allow:
- dependency-type: "development"
ignore:
- dependency-name: "phpstan/*"
- dependency-name: "phpunit/phpunit"
versions: [ ">= 10.0.0" ]
- dependency-name: "rawr/cross-data-providers"
- dependency-name: "rector/rector"
versioning-strategy: "increase"
commit-message:
prefix: "[Dependabot] "
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
"require-dev": {
"php-parallel-lint/php-parallel-lint": "1.4.0",
"phpstan/extension-installer": "1.4.3",
"phpstan/phpstan": "1.12.9",
"phpstan/phpstan-phpunit": "1.4.0",
"phpstan/phpstan-strict-rules": "1.6.1",
"phpstan/phpstan": "1.12.12 || 2.0.3",
"phpstan/phpstan-phpunit": "1.4.1 || 2.0.1",
"phpstan/phpstan-strict-rules": "1.6.1 || 2.0.0",
"phpunit/phpunit": "9.6.22",
"rawr/cross-data-providers": "2.4.0",
"rawr/phpunit-data-provider": "3.3.0",
"rector/rector": "1.2.10"
"rector/rector": "1.2.10 || 2.0.0"
},
"prefer-stable": true,
"autoload": {
Expand Down
251 changes: 232 additions & 19 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,96 +1,309 @@
parameters:
ignoreErrors:
-
message: "#^Method Pelago\\\\Emogrifier\\\\CssInliner\\:\\:getAllNodesWithStyleAttribute\\(\\) return type with generic class DOMNodeList does not specify its types\\: TNode$#"
message: '#^Method Pelago\\Emogrifier\\Caching\\SimpleStringCache\:\:set\(\) has BadMethodCallException in PHPDoc @throws tag but it''s not thrown\.$#'
identifier: throws.unusedType
count: 1
path: src/Caching/SimpleStringCache.php

-
message: '#^PHPDoc tag @var with type Sabberworm\\CSS\\Renderable is not subtype of type Sabberworm\\CSS\\CSSList\\CSSList\|Sabberworm\\CSS\\Property\\Charset\|Sabberworm\\CSS\\Property\\Import\|Sabberworm\\CSS\\RuleSet\\RuleSet\.$#'
identifier: varTag.type
count: 2
path: src/Css/CssDocument.php

-
message: '#^Method Pelago\\Emogrifier\\CssInliner\:\:getAllNodesWithStyleAttribute\(\) return type with generic class DOMNodeList does not specify its types\: TNode$#'
identifier: missingType.generics
count: 1
path: src/CssInliner.php

-
message: '#^Only numeric types are allowed in \*, int\|null given on the right side\.$#'
identifier: mul.rightNonNumeric
count: 1
path: src/CssInliner.php

-
message: "#^Parameter \\#1 \\$html of method Pelago\\\\Emogrifier\\\\HtmlProcessor\\\\AbstractHtmlProcessor\\:\\:removeSelfClosingTagsClosingTags\\(\\) expects string, string\\|false given\\.$#"
message: '#^Parameter \#1 \$html of method Pelago\\Emogrifier\\HtmlProcessor\\AbstractHtmlProcessor\:\:removeSelfClosingTagsClosingTags\(\) expects string, string\|false given\.$#'
identifier: argument.type
count: 2
path: src/HtmlProcessor/AbstractHtmlProcessor.php

-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
message: '#^Unsafe usage of new static\(\)\.$#'
identifier: new.static
count: 2
path: src/HtmlProcessor/AbstractHtmlProcessor.php

-
message: "#^Method Pelago\\\\Emogrifier\\\\HtmlProcessor\\\\CssToAttributeConverter\\:\\:getAllNodesWithStyleAttribute\\(\\) return type with generic class DOMNodeList does not specify its types\\: TNode$#"
message: '#^Method Pelago\\Emogrifier\\HtmlProcessor\\CssToAttributeConverter\:\:getAllNodesWithStyleAttribute\(\) return type with generic class DOMNodeList does not specify its types\: TNode$#'
identifier: missingType.generics
count: 1
path: src/HtmlProcessor/CssToAttributeConverter.php

-
message: "#^Method Pelago\\\\Emogrifier\\\\HtmlProcessor\\\\CssToAttributeConverter\\:\\:getAllNodesWithStyleAttribute\\(\\) should return DOMNodeList but returns DOMNodeList\\<DOMNode\\>\\|false\\.$#"
message: '#^Method Pelago\\Emogrifier\\HtmlProcessor\\CssToAttributeConverter\:\:getAllNodesWithStyleAttribute\(\) should return DOMNodeList but returns DOMNodeList\<DOMNode\>\|false\.$#'
identifier: return.type
count: 1
path: src/HtmlProcessor/CssToAttributeConverter.php

-
message: "#^Argument of an invalid type DOMNodeList\\<DOMNode\\>\\|false supplied for foreach, only iterables are supported\\.$#"
message: '#^Argument of an invalid type DOMNodeList\<DOMNode\>\|false supplied for foreach, only iterables are supported\.$#'
identifier: foreach.nonIterable
count: 1
path: src/HtmlProcessor/HtmlPruner.php

-
message: '#^Cannot access property \$length on DOMNodeList\<DOMNode\>\|false\.$#'
identifier: property.nonObject
count: 1
path: src/HtmlProcessor/HtmlPruner.php

-
message: "#^Cannot access property \\$length on DOMNodeList\\<DOMNode\\>\\|false\\.$#"
message: '#^Method Pelago\\Emogrifier\\HtmlProcessor\\HtmlPruner\:\:removeClassAttributeFromElements\(\) has parameter \$elements with generic class DOMNodeList but does not specify its types\: TNode$#'
identifier: missingType.generics
count: 1
path: src/HtmlProcessor/HtmlPruner.php

-
message: "#^Method Pelago\\\\Emogrifier\\\\HtmlProcessor\\\\HtmlPruner\\:\\:removeClassAttributeFromElements\\(\\) has parameter \\$elements with generic class DOMNodeList but does not specify its types\\: TNode$#"
message: '#^Method Pelago\\Emogrifier\\HtmlProcessor\\HtmlPruner\:\:removeClassesFromElements\(\) has parameter \$elements with generic class DOMNodeList but does not specify its types\: TNode$#'
identifier: missingType.generics
count: 1
path: src/HtmlProcessor/HtmlPruner.php

-
message: "#^Method Pelago\\\\Emogrifier\\\\HtmlProcessor\\\\HtmlPruner\\:\\:removeClassesFromElements\\(\\) has parameter \\$elements with generic class DOMNodeList but does not specify its types\\: TNode$#"
message: '#^Offset 1 might not exist on array\<int, array\<int, string\>\>\|null\.$#'
identifier: offsetAccess.notFound
count: 1
path: src/HtmlProcessor/HtmlPruner.php

-
message: "#^Parameter \\#1 \\$elements of method Pelago\\\\Emogrifier\\\\HtmlProcessor\\\\HtmlPruner\\:\\:removeClassAttributeFromElements\\(\\) expects DOMNodeList, DOMNodeList\\<DOMNode\\>\\|false given\\.$#"
message: '#^Parameter \#1 \$elements of method Pelago\\Emogrifier\\HtmlProcessor\\HtmlPruner\:\:removeClassAttributeFromElements\(\) expects DOMNodeList, DOMNodeList\<DOMNode\>\|false given\.$#'
identifier: argument.type
count: 1
path: src/HtmlProcessor/HtmlPruner.php

-
message: "#^Parameter \\#1 \\$elements of method Pelago\\\\Emogrifier\\\\HtmlProcessor\\\\HtmlPruner\\:\\:removeClassesFromElements\\(\\) expects DOMNodeList, DOMNodeList\\<DOMNode\\>\\|false given\\.$#"
message: '#^Parameter \#1 \$elements of method Pelago\\Emogrifier\\HtmlProcessor\\HtmlPruner\:\:removeClassesFromElements\(\) expects DOMNodeList, DOMNodeList\<DOMNode\>\|false given\.$#'
identifier: argument.type
count: 1
path: src/HtmlProcessor/HtmlPruner.php

-
message: "#^Property object\\{media\\: string, ruleBlocks\\: array\\<int, object\\{selectorsAsKeys\\: array\\<string, \\(int\\|string\\)\\>, declarationsBlock\\: string\\}\\>\\}\\:\\:\\$ruleBlocks is not writable\\.$#"
message: '#^Property object\{media\: string, ruleBlocks\: array\<int, object\{selectorsAsKeys\: array\<string, \(int\|string\)\>, declarationsBlock\: string\}\>\}\:\:\$ruleBlocks is not writable\.$#'
identifier: assign.propertyReadOnly
count: 1
path: src/Utilities/CssConcatenator.php

-
message: "#^Property object\\{selectorsAsKeys\\: array\\<string, \\(int\\|string\\)\\>, declarationsBlock\\: string\\}\\:\\:\\$declarationsBlock is not writable\\.$#"
message: '#^Property object\{selectorsAsKeys\: array\<string, \(int\|string\)\>, declarationsBlock\: string\}\:\:\$declarationsBlock is not writable\.$#'
identifier: assign.propertyReadOnly
count: 1
path: src/Utilities/CssConcatenator.php

-
message: "#^Property object\\{selectorsAsKeys\\: array\\<string, \\(int\\|string\\)\\>, declarationsBlock\\: string\\}\\:\\:\\$selectorsAsKeys is not writable\\.$#"
message: '#^Property object\{selectorsAsKeys\: array\<string, \(int\|string\)\>, declarationsBlock\: string\}\:\:\$selectorsAsKeys is not writable\.$#'
identifier: assign.propertyReadOnly
count: 1
path: src/Utilities/CssConcatenator.php

-
message: "#^Parameter \\#1 \\$array of function array_filter expects array, mixed given\\.$#"
message: '#^Offset 1 might not exist on array\<int, string\>\|null\.$#'
identifier: offsetAccess.notFound
count: 1
path: src/Utilities/DeclarationBlockParser.php

-
message: '#^Offset 2 might not exist on array\<int, string\>\|null\.$#'
identifier: offsetAccess.notFound
count: 1
path: src/Utilities/DeclarationBlockParser.php

-
message: '#^Method Pelago\\Emogrifier\\Utilities\\Preg\:\:match\(\) never assigns null to &\$matches so it can be removed from the by\-ref type\.$#'
identifier: parameterByRef.unusedType
count: 1
path: src/Utilities/Preg.php

-
message: '#^Method Pelago\\Emogrifier\\Utilities\\Preg\:\:matchAll\(\) never assigns null to &\$matches so it can be removed from the by\-ref type\.$#'
identifier: parameterByRef.unusedType
count: 1
path: src/Utilities/Preg.php

-
message: '#^Method Pelago\\Emogrifier\\Utilities\\Preg\:\:replace\(\) never assigns null to &\$count so it can be removed from the by\-ref type\.$#'
identifier: parameterByRef.unusedType
count: 1
path: src/Utilities/Preg.php

-
message: '#^Method Pelago\\Emogrifier\\Utilities\\Preg\:\:replaceCallback\(\) never assigns null to &\$count so it can be removed from the by\-ref type\.$#'
identifier: parameterByRef.unusedType
count: 1
path: src/Utilities/Preg.php

-
message: '#^Parameter \#1 \$array of function array_flip expects array\<int\|string\>, array\<string, mixed\> given\.$#'
identifier: argument.type
count: 1
path: src/Utilities/Preg.php

-
message: "#^Parameter \\#2 \\$callback of function array_filter expects \\(callable\\(mixed\\)\\: bool\\)\\|null, Closure\\(string\\)\\: bool given\\.$#"
message: '#^Parameter &\$matches by\-ref type of method Pelago\\Emogrifier\\Utilities\\Preg\:\:match\(\) expects array\<int, string\>\|null, array\<string\> given\.$#'
identifier: parameterByRef.type
count: 1
path: src/Utilities/Preg.php

-
message: "#^Parameter \\#1 \\$string of function trim expects string, string\\|false given\\.$#"
message: '#^Parameter &\$matches by\-ref type of method Pelago\\Emogrifier\\Utilities\\Preg\:\:matchAll\(\) expects array\<int, array\<int, string\>\>\|null, array\<list\<string\>\> given\.$#'
identifier: parameterByRef.type
count: 1
path: src/Utilities/Preg.php

-
message: '''
#^@dataProvider provideInvalidAtCharsetRuleWhichCausesException
Invalid related method not found\.$#
'''
identifier: phpunit.dataProviderMethod
count: 1
path: tests/Unit/Css/CssDocumentTest.php

-
message: '''
#^@dataProvider provideInvalidNonConditionalAtRuleWhichCausesException
Invalid related method not found\.$#
'''
identifier: phpunit.dataProviderMethod
count: 1
path: tests/Unit/Css/CssDocumentTest.php

-
message: '#^Offset 0 might not exist on array\<int, string\>\|null\.$#'
identifier: offsetAccess.notFound
count: 1
path: tests/Unit/Css/CssDocumentTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Pelago\\\\Emogrifier\\\\CssInliner'' and Pelago\\Emogrifier\\CssInliner will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: tests/Unit/CssInlinerTest.php

-
message: "#^Parameter \\#1 \\$string of function strtolower expects string, string\\|false given\\.$#"
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Pelago\\\\Emogrifier\\\\HtmlProcessor\\\\AbstractHtmlProcessor'' and Pelago\\Emogrifier\\CssInliner will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: tests/Unit/CssInlinerTest.php

-
message: '#^Parameter \#1 \$string of function trim expects string, string\|false given\.$#'
identifier: argument.type
count: 1
path: tests/Unit/CssInlinerTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''DOMDocument'' and DOMDocument will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: tests/Unit/HtmlProcessor/AbstractHtmlProcessorTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Pelago\\\\Emogrifier\\\\HtmlProcessor\\\\AbstractHtmlProcessor'' and Pelago\\Emogrifier\\Tests\\Unit\\HtmlProcessor\\Fixtures\\TestingHtmlProcessor will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 2
path: tests/Unit/HtmlProcessor/AbstractHtmlProcessorTest.php

-
message: "#^Parameter \\#2 \\$actual of static method Pelago\\\\Emogrifier\\\\Tests\\\\Unit\\\\HtmlProcessor\\\\AbstractHtmlProcessorTest\\:\\:assertEqualsHtml\\(\\) expects string, string\\|false given\\.$#"
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Pelago\\\\Emogrifier\\\\Tests\\\\Unit\\\\HtmlProcessor\\\\Fixtures\\\\TestingHtmlProcessor'' and Pelago\\Emogrifier\\Tests\\Unit\\HtmlProcessor\\Fixtures\\TestingHtmlProcessor will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 2
path: tests/Unit/HtmlProcessor/AbstractHtmlProcessorTest.php

-
message: '#^Parameter \#1 \$string of function strtolower expects string, string\|false given\.$#'
identifier: argument.type
count: 1
path: tests/Unit/HtmlProcessor/AbstractHtmlProcessorTest.php

-
message: '#^Parameter \#2 \$actual of static method Pelago\\Emogrifier\\Tests\\Unit\\HtmlProcessor\\AbstractHtmlProcessorTest\:\:assertEqualsHtml\(\) expects string, string\|false given\.$#'
identifier: argument.type
count: 1
path: tests/Unit/HtmlProcessor/AbstractHtmlProcessorTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Pelago\\\\Emogrifier\\\\HtmlProcessor\\\\AbstractHtmlProcessor'' and Pelago\\Emogrifier\\HtmlProcessor\\CssToAttributeConverter will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: tests/Unit/HtmlProcessor/CssToAttributeConverterTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Pelago\\\\Emogrifier\\\\HtmlProcessor\\\\CssToAttributeConverter'' and Pelago\\Emogrifier\\HtmlProcessor\\CssToAttributeConverter will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 2
path: tests/Unit/HtmlProcessor/CssToAttributeConverterTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Pelago\\\\Emogrifier\\\\HtmlProcessor\\\\AbstractHtmlProcessor'' and Pelago\\Emogrifier\\HtmlProcessor\\HtmlNormalizer will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: tests/Unit/HtmlProcessor/HtmlNormalizerTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Pelago\\\\Emogrifier\\\\HtmlProcessor\\\\HtmlNormalizer'' and Pelago\\Emogrifier\\HtmlProcessor\\HtmlNormalizer will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 2
path: tests/Unit/HtmlProcessor/HtmlNormalizerTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Pelago\\\\Emogrifier\\\\HtmlProcessor\\\\AbstractHtmlProcessor'' and Pelago\\Emogrifier\\HtmlProcessor\\HtmlPruner will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: tests/Unit/HtmlProcessor/HtmlPrunerTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Pelago\\\\Emogrifier\\\\HtmlProcessor\\\\HtmlPruner'' and Pelago\\Emogrifier\\HtmlProcessor\\HtmlPruner will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 2
path: tests/Unit/HtmlProcessor/HtmlPrunerTest.php

-
message: '#^Offset 1 might not exist on array\<int, array\<int, string\>\>\|null\.$#'
identifier: offsetAccess.notFound
count: 1
path: tests/Unit/HtmlProcessor/HtmlPrunerTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''PHPUnit\\\\Framework\\\\Constraint\\\\Constraint'' and Pelago\\Emogrifier\\Tests\\Support\\Constraint\\IsEquivalentCss will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: tests/Unit/Support/Traits/AssertCssTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''PHPUnit\\\\Framework\\\\Constraint\\\\Constraint'' and Pelago\\Emogrifier\\Tests\\Support\\Constraint\\StringContainsCss will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: tests/Unit/Support/Traits/AssertCssTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''PHPUnit\\\\Framework\\\\Constraint\\\\Constraint'' and Pelago\\Emogrifier\\Tests\\Support\\Constraint\\StringContainsCssCount will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: tests/Unit/Support/Traits/AssertCssTest.php

-
message: '#^Parameter \#1 \$array of function array_filter expects array, array\<int, array\<int, string\>\>\|null given\.$#'
identifier: argument.type
count: 1
path: tests/Unit/Utilities/PregTest.php

-
message: '#^Parameter \#2 \$haystack of static method PHPUnit\\Framework\\Assert\:\:assertCount\(\) expects Countable\|iterable, array\<int, array\<int, string\>\>\|null given\.$#'
identifier: argument.type
count: 1
path: tests/Unit/Utilities/PregTest.php
3 changes: 0 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ parameters:
paths:
- src
- tests

# Allow instanceof checks, particularly in tests
checkAlwaysTrueCheckTypeFunctionCall: false

0 comments on commit e6c33d9

Please sign in to comment.