Skip to content

Commit 62a2e65

Browse files
authored
[TASK] Add strict PHPStan rules (#909)
Now we are using the same static analysis tools as our sister project.
1 parent 845b457 commit 62a2e65

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"phpstan/extension-installer": "1.4.3",
3232
"phpstan/phpstan": "1.12.16 || 2.1.2",
3333
"phpstan/phpstan-phpunit": "1.4.2 || 2.0.4",
34+
"phpstan/phpstan-strict-rules": "1.6.2 || 2.0.3",
3435
"phpunit/phpunit": "8.5.41",
3536
"rector/rector": "1.2.10 || 2.0.7"
3637
},

config/phpstan-baseline.neon

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ parameters:
1212
count: 1
1313
path: ../src/CSSList/AtRuleBlockList.php
1414

15+
-
16+
message: '#^Only booleans are allowed in an if condition, string given\.$#'
17+
identifier: if.condNotBoolean
18+
count: 1
19+
path: ../src/CSSList/AtRuleBlockList.php
20+
1521
-
1622
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\.$#'
1723
identifier: parameterByRef.type
@@ -48,6 +54,24 @@ parameters:
4854
count: 1
4955
path: ../src/CSSList/CSSList.php
5056

57+
-
58+
message: '#^Loose comparison via "\!\=" is not allowed\.$#'
59+
identifier: notEqual.notAllowed
60+
count: 1
61+
path: ../src/CSSList/CSSList.php
62+
63+
-
64+
message: '#^Loose comparison via "\=\=" is not allowed\.$#'
65+
identifier: equal.notAllowed
66+
count: 1
67+
path: ../src/CSSList/CSSList.php
68+
69+
-
70+
message: '#^Short ternary operator is not allowed\. Use null coalesce operator if applicable or consider using long ternary\.$#'
71+
identifier: ternary.shortNotAllowed
72+
count: 1
73+
path: ../src/CSSList/CSSList.php
74+
5175
-
5276
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
5377
identifier: method.notFound
@@ -66,6 +90,12 @@ parameters:
6690
count: 1
6791
path: ../src/CSSList/KeyFrame.php
6892

93+
-
94+
message: '#^Variable property access on \$this\(Sabberworm\\CSS\\OutputFormat\)\.$#'
95+
identifier: property.dynamicName
96+
count: 4
97+
path: ../src/OutputFormat.php
98+
6999
-
70100
message: '#^Default value of the parameter \#2 \$bIncludeEnd \(false\) of method Sabberworm\\CSS\\Parsing\\ParserState\:\:consumeUntil\(\) is incompatible with type string\.$#'
71101
identifier: parameter.defaultValue
@@ -78,6 +108,24 @@ parameters:
78108
count: 1
79109
path: ../src/Parsing/ParserState.php
80110

111+
-
112+
message: '#^Loose comparison via "\=\=" is not allowed\.$#'
113+
identifier: equal.notAllowed
114+
count: 1
115+
path: ../src/Parsing/ParserState.php
116+
117+
-
118+
message: '#^Only booleans are allowed in a negated boolean, string given\.$#'
119+
identifier: booleanNot.exprNotBoolean
120+
count: 1
121+
path: ../src/Parsing/ParserState.php
122+
123+
-
124+
message: '#^Only booleans are allowed in an if condition, string given\.$#'
125+
identifier: if.condNotBoolean
126+
count: 1
127+
path: ../src/Parsing/ParserState.php
128+
81129
-
82130
message: '#^PHPDoc tag @return with type array\<int, Sabberworm\\CSS\\Comment\\Comment\>\|void is not subtype of native type array\.$#'
83131
identifier: return.phpDocType
@@ -90,6 +138,12 @@ parameters:
90138
count: 1
91139
path: ../src/Property/CSSNamespace.php
92140

141+
-
142+
message: '#^Only booleans are allowed in an if condition, string given\.$#'
143+
identifier: if.condNotBoolean
144+
count: 1
145+
path: ../src/Property/CSSNamespace.php
146+
93147
-
94148
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\(\)$#'
95149
identifier: method.childReturnType
@@ -114,6 +168,12 @@ parameters:
114168
count: 1
115169
path: ../src/Property/Import.php
116170

171+
-
172+
message: '#^Only booleans are allowed in an if condition, string given\.$#'
173+
identifier: if.condNotBoolean
174+
count: 1
175+
path: ../src/Property/Import.php
176+
117177
-
118178
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\(\)$#'
119179
identifier: method.childReturnType
@@ -132,6 +192,18 @@ parameters:
132192
count: 1
133193
path: ../src/Rule/Rule.php
134194

195+
-
196+
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
197+
identifier: empty.notAllowed
198+
count: 1
199+
path: ../src/Rule/Rule.php
200+
201+
-
202+
message: '#^Only booleans are allowed in an if condition, Sabberworm\\CSS\\Value\\RuleValueList\|string\|null given\.$#'
203+
identifier: if.condNotBoolean
204+
count: 1
205+
path: ../src/Rule/Rule.php
206+
135207
-
136208
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
137209
identifier: method.notFound
@@ -144,6 +216,12 @@ parameters:
144216
count: 1
145217
path: ../src/RuleSet/AtRuleSet.php
146218

219+
-
220+
message: '#^Only booleans are allowed in an if condition, string given\.$#'
221+
identifier: if.condNotBoolean
222+
count: 1
223+
path: ../src/RuleSet/AtRuleSet.php
224+
147225
-
148226
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
149227
identifier: method.notFound
@@ -174,6 +252,24 @@ parameters:
174252
count: 1
175253
path: ../src/RuleSet/DeclarationBlock.php
176254

255+
-
256+
message: '#^Foreach overwrites \$mSelector with its value variable\.$#'
257+
identifier: foreach.valueOverwrite
258+
count: 1
259+
path: ../src/RuleSet/DeclarationBlock.php
260+
261+
-
262+
message: '#^Loose comparison via "\!\=" is not allowed\.$#'
263+
identifier: notEqual.notAllowed
264+
count: 1
265+
path: ../src/RuleSet/DeclarationBlock.php
266+
267+
-
268+
message: '#^Loose comparison via "\=\=" is not allowed\.$#'
269+
identifier: equal.notAllowed
270+
count: 1
271+
path: ../src/RuleSet/DeclarationBlock.php
272+
177273
-
178274
message: '#^Argument of an invalid type Sabberworm\\CSS\\Rule\\Rule supplied for foreach, only iterables are supported\.$#'
179275
identifier: foreach.nonIterable
@@ -210,6 +306,30 @@ parameters:
210306
count: 1
211307
path: ../src/RuleSet/RuleSet.php
212308

309+
-
310+
message: '#^Only booleans are allowed in a negated boolean, string\|null given\.$#'
311+
identifier: booleanNot.exprNotBoolean
312+
count: 2
313+
path: ../src/RuleSet/RuleSet.php
314+
315+
-
316+
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\(\)$#'
317+
identifier: method.childParameterType
318+
count: 1
319+
path: ../src/RuleSet/RuleSet.php
320+
321+
-
322+
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\(\)$#'
323+
identifier: method.childParameterType
324+
count: 1
325+
path: ../src/RuleSet/RuleSet.php
326+
327+
-
328+
message: '#^Loose comparison via "\!\=" is not allowed\.$#'
329+
identifier: notEqual.notAllowed
330+
count: 3
331+
path: ../src/Value/CalcFunction.php
332+
213333
-
214334
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
215335
identifier: method.notFound
@@ -234,12 +354,30 @@ parameters:
234354
count: 1
235355
path: ../src/Value/Color.php
236356

357+
-
358+
message: '#^Call to method Sabberworm\\CSS\\Value\\Color\:\:hasNoneAsComponentValue\(\) with incorrect case\: HasNoneAsComponentValue$#'
359+
identifier: method.nameCase
360+
count: 1
361+
path: ../src/Value/Color.php
362+
237363
-
238364
message: '#^Cannot call method getSize\(\) on Sabberworm\\CSS\\Value\\Value\|string\.$#'
239365
identifier: method.nonObject
240366
count: 3
241367
path: ../src/Value/Color.php
242368

369+
-
370+
message: '#^Loose comparison via "\=\=" is not allowed\.$#'
371+
identifier: equal.notAllowed
372+
count: 3
373+
path: ../src/Value/Color.php
374+
375+
-
376+
message: '#^Loose comparison via "\!\=" is not allowed\.$#'
377+
identifier: notEqual.notAllowed
378+
count: 1
379+
path: ../src/Value/Size.php
380+
243381
-
244382
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
245383
identifier: method.notFound
@@ -258,3 +396,15 @@ parameters:
258396
count: 1
259397
path: ../src/Value/ValueList.php
260398

399+
-
400+
message: '#^Dynamic call to static method Sabberworm\\CSS\\Tests\\ParserTest\:\:parsedStructureForFile\(\)\.$#'
401+
identifier: staticMethod.dynamicCall
402+
count: 2
403+
path: ../tests/ParserTest.php
404+
405+
-
406+
message: '#^Loose comparison via "\=\=" is not allowed\.$#'
407+
identifier: equal.notAllowed
408+
count: 11
409+
path: ../tests/ParserTest.php
410+

0 commit comments

Comments
 (0)