Skip to content

[TASK] Add strict PHPStan rules #909

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

Merged
merged 1 commit into from
Feb 13, 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: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"phpstan/extension-installer": "1.4.3",
"phpstan/phpstan": "1.12.16 || 2.1.2",
"phpstan/phpstan-phpunit": "1.4.2 || 2.0.4",
"phpstan/phpstan-strict-rules": "1.6.2 || 2.0.3",
"phpunit/phpunit": "8.5.41",
"rector/rector": "1.2.10 || 2.0.7"
},
Expand Down
150 changes: 150 additions & 0 deletions config/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ parameters:
count: 1
path: ../src/CSSList/AtRuleBlockList.php

-
message: '#^Only booleans are allowed in an if condition, string given\.$#'
identifier: if.condNotBoolean
count: 1
path: ../src/CSSList/AtRuleBlockList.php

-
message: '#^Parameter &\$result by\-ref type of method Sabberworm\\CSS\\CSSList\\CSSBlockList\:\:allSelectors\(\) expects array\<int, Sabberworm\\CSS\\Property\\Selector\>, array\<int, Sabberworm\\CSS\\Property\\Selector\|string\> given\.$#'
identifier: parameterByRef.type
Expand Down Expand Up @@ -48,6 +54,24 @@ parameters:
count: 1
path: ../src/CSSList/CSSList.php

-
message: '#^Loose comparison via "\!\=" is not allowed\.$#'
identifier: notEqual.notAllowed
count: 1
path: ../src/CSSList/CSSList.php

-
message: '#^Loose comparison via "\=\=" is not allowed\.$#'
identifier: equal.notAllowed
count: 1
path: ../src/CSSList/CSSList.php

-
message: '#^Short ternary operator is not allowed\. Use null coalesce operator if applicable or consider using long ternary\.$#'
identifier: ternary.shortNotAllowed
count: 1
path: ../src/CSSList/CSSList.php

-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
identifier: method.notFound
Expand All @@ -66,6 +90,12 @@ parameters:
count: 1
path: ../src/CSSList/KeyFrame.php

-
message: '#^Variable property access on \$this\(Sabberworm\\CSS\\OutputFormat\)\.$#'
identifier: property.dynamicName
count: 4
path: ../src/OutputFormat.php

-
message: '#^Default value of the parameter \#2 \$bIncludeEnd \(false\) of method Sabberworm\\CSS\\Parsing\\ParserState\:\:consumeUntil\(\) is incompatible with type string\.$#'
identifier: parameter.defaultValue
Expand All @@ -78,6 +108,24 @@ parameters:
count: 1
path: ../src/Parsing/ParserState.php

-
message: '#^Loose comparison via "\=\=" is not allowed\.$#'
identifier: equal.notAllowed
count: 1
path: ../src/Parsing/ParserState.php

-
message: '#^Only booleans are allowed in a negated boolean, string given\.$#'
identifier: booleanNot.exprNotBoolean
count: 1
path: ../src/Parsing/ParserState.php

-
message: '#^Only booleans are allowed in an if condition, string given\.$#'
identifier: if.condNotBoolean
count: 1
path: ../src/Parsing/ParserState.php

-
message: '#^PHPDoc tag @return with type array\<int, Sabberworm\\CSS\\Comment\\Comment\>\|void is not subtype of native type array\.$#'
identifier: return.phpDocType
Expand All @@ -90,6 +138,12 @@ parameters:
count: 1
path: ../src/Property/CSSNamespace.php

-
message: '#^Only booleans are allowed in an if condition, string given\.$#'
identifier: if.condNotBoolean
count: 1
path: ../src/Property/CSSNamespace.php

-
message: '#^Return type \(array\<int, string\>\) of method Sabberworm\\CSS\\Property\\CSSNamespace\:\:atRuleArgs\(\) should be compatible with return type \(string\|null\) of method Sabberworm\\CSS\\Property\\AtRule\:\:atRuleArgs\(\)$#'
identifier: method.childReturnType
Expand All @@ -114,6 +168,12 @@ parameters:
count: 1
path: ../src/Property/Import.php

-
message: '#^Only booleans are allowed in an if condition, string given\.$#'
identifier: if.condNotBoolean
count: 1
path: ../src/Property/Import.php

-
message: '#^Return type \(array\<int, Sabberworm\\CSS\\Value\\URL\|string\>\) of method Sabberworm\\CSS\\Property\\Import\:\:atRuleArgs\(\) should be compatible with return type \(string\|null\) of method Sabberworm\\CSS\\Property\\AtRule\:\:atRuleArgs\(\)$#'
identifier: method.childReturnType
Expand All @@ -132,6 +192,18 @@ parameters:
count: 1
path: ../src/Rule/Rule.php

-
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
identifier: empty.notAllowed
count: 1
path: ../src/Rule/Rule.php

-
message: '#^Only booleans are allowed in an if condition, Sabberworm\\CSS\\Value\\RuleValueList\|string\|null given\.$#'
identifier: if.condNotBoolean
count: 1
path: ../src/Rule/Rule.php

-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
identifier: method.notFound
Expand All @@ -144,6 +216,12 @@ parameters:
count: 1
path: ../src/RuleSet/AtRuleSet.php

-
message: '#^Only booleans are allowed in an if condition, string given\.$#'
identifier: if.condNotBoolean
count: 1
path: ../src/RuleSet/AtRuleSet.php

-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
identifier: method.notFound
Expand Down Expand Up @@ -174,6 +252,24 @@ parameters:
count: 1
path: ../src/RuleSet/DeclarationBlock.php

-
message: '#^Foreach overwrites \$mSelector with its value variable\.$#'
identifier: foreach.valueOverwrite
count: 1
path: ../src/RuleSet/DeclarationBlock.php

-
message: '#^Loose comparison via "\!\=" is not allowed\.$#'
identifier: notEqual.notAllowed
count: 1
path: ../src/RuleSet/DeclarationBlock.php

-
message: '#^Loose comparison via "\=\=" is not allowed\.$#'
identifier: equal.notAllowed
count: 1
path: ../src/RuleSet/DeclarationBlock.php

-
message: '#^Argument of an invalid type Sabberworm\\CSS\\Rule\\Rule supplied for foreach, only iterables are supported\.$#'
identifier: foreach.nonIterable
Expand Down Expand Up @@ -210,6 +306,30 @@ parameters:
count: 1
path: ../src/RuleSet/RuleSet.php

-
message: '#^Only booleans are allowed in a negated boolean, string\|null given\.$#'
identifier: booleanNot.exprNotBoolean
count: 2
path: ../src/RuleSet/RuleSet.php

-
message: '#^Parameter \#1 \$comments \(array\<string, Sabberworm\\CSS\\Comment\\Comment\>\) of method Sabberworm\\CSS\\RuleSet\\RuleSet\:\:addComments\(\) should be contravariant with parameter \$comments \(array\<Sabberworm\\CSS\\Comment\\Comment\>\) of method Sabberworm\\CSS\\Comment\\Commentable\:\:addComments\(\)$#'
identifier: method.childParameterType
count: 1
path: ../src/RuleSet/RuleSet.php

-
message: '#^Parameter \#1 \$comments \(array\<string, Sabberworm\\CSS\\Comment\\Comment\>\) of method Sabberworm\\CSS\\RuleSet\\RuleSet\:\:setComments\(\) should be contravariant with parameter \$comments \(array\<Sabberworm\\CSS\\Comment\\Comment\>\) of method Sabberworm\\CSS\\Comment\\Commentable\:\:setComments\(\)$#'
identifier: method.childParameterType
count: 1
path: ../src/RuleSet/RuleSet.php

-
message: '#^Loose comparison via "\!\=" is not allowed\.$#'
identifier: notEqual.notAllowed
count: 3
path: ../src/Value/CalcFunction.php

-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
identifier: method.notFound
Expand All @@ -234,12 +354,30 @@ parameters:
count: 1
path: ../src/Value/Color.php

-
message: '#^Call to method Sabberworm\\CSS\\Value\\Color\:\:hasNoneAsComponentValue\(\) with incorrect case\: HasNoneAsComponentValue$#'
identifier: method.nameCase
count: 1
path: ../src/Value/Color.php

-
message: '#^Cannot call method getSize\(\) on Sabberworm\\CSS\\Value\\Value\|string\.$#'
identifier: method.nonObject
count: 3
path: ../src/Value/Color.php

-
message: '#^Loose comparison via "\=\=" is not allowed\.$#'
identifier: equal.notAllowed
count: 3
path: ../src/Value/Color.php

-
message: '#^Loose comparison via "\!\=" is not allowed\.$#'
identifier: notEqual.notAllowed
count: 1
path: ../src/Value/Size.php

-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
identifier: method.notFound
Expand All @@ -258,3 +396,15 @@ parameters:
count: 1
path: ../src/Value/ValueList.php

-
message: '#^Dynamic call to static method Sabberworm\\CSS\\Tests\\ParserTest\:\:parsedStructureForFile\(\)\.$#'
identifier: staticMethod.dynamicCall
count: 2
path: ../tests/ParserTest.php

-
message: '#^Loose comparison via "\=\=" is not allowed\.$#'
identifier: equal.notAllowed
count: 11
path: ../tests/ParserTest.php