Skip to content

[TASK] Add PHPStan rules from Rector Type Perfect #939

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 16, 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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"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"
"rector/rector": "1.2.10 || 2.0.7",
"rector/type-perfect": "1.0.0 || 2.0.2"
},
"suggest": {
"ext-mbstring": "for parsing UTF-8 CSS"
Expand Down
114 changes: 114 additions & 0 deletions config/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ parameters:
count: 1
path: ../src/CSSList/Document.php

-
message: '#^Parameters should have "string\|null" types as the only types passed to this method$#'
identifier: typePerfect.narrowPublicClassMethodParamType
count: 1
path: ../src/CSSList/Document.php

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

-
message: '#^Parameters should have "string" types as the only types passed to this method$#'
identifier: typePerfect.narrowPublicClassMethodParamType
count: 2
path: ../src/CSSList/KeyFrame.php

-
message: '#^Parameters should have "string\|string" types as the only types passed to this method$#'
identifier: typePerfect.narrowPublicClassMethodParamType
count: 1
path: ../src/OutputFormat.php

-
message: '#^Returning false in non return bool class method\. Use null with type\|null instead or add bool return type$#'
identifier: typePerfect.nullOverFalse
count: 1
path: ../src/OutputFormat.php

-
message: '#^Variable property access on \$this\(Sabberworm\\CSS\\OutputFormat\)\.$#'
identifier: property.dynamicName
Expand Down Expand Up @@ -132,6 +156,30 @@ parameters:
count: 1
path: ../src/Parsing/ParserState.php

-
message: '#^Parameters should have "bool" types as the only types passed to this method$#'
identifier: typePerfect.narrowPublicClassMethodParamType
count: 2
path: ../src/Parsing/ParserState.php

-
message: '#^Parameters should have "int" types as the only types passed to this method$#'
identifier: typePerfect.narrowPublicClassMethodParamType
count: 2
path: ../src/Parsing/ParserState.php

-
message: '#^Parameters should have "string" types as the only types passed to this method$#'
identifier: typePerfect.narrowPublicClassMethodParamType
count: 1
path: ../src/Parsing/ParserState.php

-
message: '#^Parameters should have "string\|int\|null" types as the only types passed to this method$#'
identifier: typePerfect.narrowPublicClassMethodParamType
count: 1
path: ../src/Parsing/ParserState.php

-
message: '#^Cannot call method render\(\) on string\.$#'
identifier: method.nonObject
Expand Down Expand Up @@ -180,6 +228,12 @@ parameters:
count: 1
path: ../src/Property/Import.php

-
message: '#^Parameters should have "string" types as the only types passed to this method$#'
identifier: typePerfect.narrowPublicClassMethodParamType
count: 1
path: ../src/Property/Selector.php

-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
identifier: method.notFound
Expand All @@ -204,6 +258,24 @@ parameters:
count: 1
path: ../src/Rule/Rule.php

-
message: '#^Parameters should have "bool" types as the only types passed to this method$#'
identifier: typePerfect.narrowPublicClassMethodParamType
count: 1
path: ../src/Rule/Rule.php

-
message: '#^Parameters should have "int\|int" types as the only types passed to this method$#'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int|int?!?

identifier: typePerfect.narrowPublicClassMethodParamType
count: 1
path: ../src/Rule/Rule.php

-
message: '#^Parameters should have "string" types as the only types passed to this method$#'
identifier: typePerfect.narrowPublicClassMethodParamType
count: 1
path: ../src/Rule/Rule.php

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

-
message: '#^Parameters should have "string" types as the only types passed to this method$#'
identifier: typePerfect.narrowPublicClassMethodParamType
count: 1
path: ../src/RuleSet/DeclarationBlock.php

-
message: '#^Returning false in non return bool class method\. Use null with type\|null instead or add bool return type$#'
identifier: typePerfect.nullOverFalse
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 @@ -324,6 +408,24 @@ parameters:
count: 1
path: ../src/RuleSet/RuleSet.php

-
message: '#^Parameters should have "Sabberworm\\CSS\\Rule\\Rule" types as the only types passed to this method$#'
identifier: typePerfect.narrowPublicClassMethodParamType
count: 1
path: ../src/RuleSet/RuleSet.php

-
message: '#^Parameters should have "string" types as the only types passed to this method$#'
identifier: typePerfect.narrowPublicClassMethodParamType
count: 1
path: ../src/RuleSet/RuleSet.php

-
message: '#^Use explicit methods over array access on object$#'
identifier: typePerfect.noArrayAccessOnObject
count: 1
path: ../src/RuleSet/RuleSet.php

-
message: '#^Loose comparison via "\!\=" is not allowed\.$#'
identifier: notEqual.notAllowed
Expand Down Expand Up @@ -372,12 +474,24 @@ parameters:
count: 3
path: ../src/Value/Color.php

-
message: '#^Provide more specific return type "Sabberworm\\CSS\\Value\\Color" over abstract one$#'
identifier: typePerfect.narrowReturnObjectType
count: 1
path: ../src/Value/Color.php

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

-
message: '#^Parameters should have "float" types as the only types passed to this method$#'
identifier: typePerfect.narrowPublicClassMethodParamType
count: 1
path: ../src/Value/Size.php

-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
identifier: method.notFound
Expand Down
7 changes: 7 additions & 0 deletions config/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ parameters:
- %currentWorkingDirectory%/bin/
- %currentWorkingDirectory%/src/
- %currentWorkingDirectory%/tests/

type_perfect:
no_mixed_property: true
no_mixed_caller: true
null_over_false: true
narrow_param: true
narrow_return: true