Skip to content

Commit d474517

Browse files
committed
[TASK] Add strict PHPStan rules
Now we are using the same static analysis tools as our sister project.
1 parent b3e83b8 commit d474517

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-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: 138 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: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:safely\(\)\.$#'
1723
identifier: method.notFound
@@ -36,6 +42,24 @@ parameters:
3642
count: 1
3743
path: ../src/CSSList/CSSList.php
3844

45+
-
46+
message: '#^Loose comparison via "\!\=" is not allowed\.$#'
47+
identifier: notEqual.notAllowed
48+
count: 1
49+
path: ../src/CSSList/CSSList.php
50+
51+
-
52+
message: '#^Loose comparison via "\=\=" is not allowed\.$#'
53+
identifier: equal.notAllowed
54+
count: 1
55+
path: ../src/CSSList/CSSList.php
56+
57+
-
58+
message: '#^Short ternary operator is not allowed\. Use null coalesce operator if applicable or consider using long ternary\.$#'
59+
identifier: ternary.shortNotAllowed
60+
count: 1
61+
path: ../src/CSSList/CSSList.php
62+
3963
-
4064
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
4165
identifier: method.notFound
@@ -54,6 +78,12 @@ parameters:
5478
count: 1
5579
path: ../src/CSSList/KeyFrame.php
5680

81+
-
82+
message: '#^Variable property access on \$this\(Sabberworm\\CSS\\OutputFormat\)\.$#'
83+
identifier: property.dynamicName
84+
count: 4
85+
path: ../src/OutputFormat.php
86+
5787
-
5888
message: '#^Default value of the parameter \#2 \$bIncludeEnd \(false\) of method Sabberworm\\CSS\\Parsing\\ParserState\:\:consumeUntil\(\) is incompatible with type string\.$#'
5989
identifier: parameter.defaultValue
@@ -66,6 +96,24 @@ parameters:
6696
count: 1
6797
path: ../src/Parsing/ParserState.php
6898

99+
-
100+
message: '#^Loose comparison via "\=\=" is not allowed\.$#'
101+
identifier: equal.notAllowed
102+
count: 1
103+
path: ../src/Parsing/ParserState.php
104+
105+
-
106+
message: '#^Only booleans are allowed in a negated boolean, string given\.$#'
107+
identifier: booleanNot.exprNotBoolean
108+
count: 1
109+
path: ../src/Parsing/ParserState.php
110+
111+
-
112+
message: '#^Only booleans are allowed in an if condition, string given\.$#'
113+
identifier: if.condNotBoolean
114+
count: 1
115+
path: ../src/Parsing/ParserState.php
116+
69117
-
70118
message: '#^PHPDoc tag @return with type array\<int, Sabberworm\\CSS\\Comment\\Comment\>\|void is not subtype of native type array\.$#'
71119
identifier: return.phpDocType
@@ -78,6 +126,12 @@ parameters:
78126
count: 1
79127
path: ../src/Property/CSSNamespace.php
80128

129+
-
130+
message: '#^Only booleans are allowed in an if condition, string given\.$#'
131+
identifier: if.condNotBoolean
132+
count: 1
133+
path: ../src/Property/CSSNamespace.php
134+
81135
-
82136
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
83137
identifier: method.notFound
@@ -96,6 +150,12 @@ parameters:
96150
count: 1
97151
path: ../src/Property/Import.php
98152

153+
-
154+
message: '#^Only booleans are allowed in an if condition, string given\.$#'
155+
identifier: if.condNotBoolean
156+
count: 1
157+
path: ../src/Property/Import.php
158+
99159
-
100160
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
101161
identifier: method.notFound
@@ -108,6 +168,18 @@ parameters:
108168
count: 1
109169
path: ../src/Rule/Rule.php
110170

171+
-
172+
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
173+
identifier: empty.notAllowed
174+
count: 1
175+
path: ../src/Rule/Rule.php
176+
177+
-
178+
message: '#^Only booleans are allowed in an if condition, Sabberworm\\CSS\\Value\\RuleValueList\|string\|null given\.$#'
179+
identifier: if.condNotBoolean
180+
count: 1
181+
path: ../src/Rule/Rule.php
182+
111183
-
112184
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
113185
identifier: method.notFound
@@ -120,6 +192,12 @@ parameters:
120192
count: 1
121193
path: ../src/RuleSet/AtRuleSet.php
122194

195+
-
196+
message: '#^Only booleans are allowed in an if condition, string given\.$#'
197+
identifier: if.condNotBoolean
198+
count: 1
199+
path: ../src/RuleSet/AtRuleSet.php
200+
123201
-
124202
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
125203
identifier: method.notFound
@@ -150,6 +228,24 @@ parameters:
150228
count: 1
151229
path: ../src/RuleSet/DeclarationBlock.php
152230

231+
-
232+
message: '#^Foreach overwrites \$mSelector with its value variable\.$#'
233+
identifier: foreach.valueOverwrite
234+
count: 1
235+
path: ../src/RuleSet/DeclarationBlock.php
236+
237+
-
238+
message: '#^Loose comparison via "\!\=" is not allowed\.$#'
239+
identifier: notEqual.notAllowed
240+
count: 1
241+
path: ../src/RuleSet/DeclarationBlock.php
242+
243+
-
244+
message: '#^Loose comparison via "\=\=" is not allowed\.$#'
245+
identifier: equal.notAllowed
246+
count: 1
247+
path: ../src/RuleSet/DeclarationBlock.php
248+
153249
-
154250
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:removeLastSemicolon\(\)\.$#'
155251
identifier: method.notFound
@@ -180,6 +276,18 @@ parameters:
180276
count: 1
181277
path: ../src/RuleSet/RuleSet.php
182278

279+
-
280+
message: '#^Only booleans are allowed in a negated boolean, string\|null given\.$#'
281+
identifier: booleanNot.exprNotBoolean
282+
count: 2
283+
path: ../src/RuleSet/RuleSet.php
284+
285+
-
286+
message: '#^Loose comparison via "\!\=" is not allowed\.$#'
287+
identifier: notEqual.notAllowed
288+
count: 3
289+
path: ../src/Value/CalcFunction.php
290+
183291
-
184292
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
185293
identifier: method.notFound
@@ -204,12 +312,30 @@ parameters:
204312
count: 1
205313
path: ../src/Value/Color.php
206314

315+
-
316+
message: '#^Call to method Sabberworm\\CSS\\Value\\Color\:\:hasNoneAsComponentValue\(\) with incorrect case\: HasNoneAsComponentValue$#'
317+
identifier: method.nameCase
318+
count: 1
319+
path: ../src/Value/Color.php
320+
207321
-
208322
message: '#^Cannot call method getSize\(\) on Sabberworm\\CSS\\Value\\Value\|string\.$#'
209323
identifier: method.nonObject
210324
count: 3
211325
path: ../src/Value/Color.php
212326

327+
-
328+
message: '#^Loose comparison via "\=\=" is not allowed\.$#'
329+
identifier: equal.notAllowed
330+
count: 3
331+
path: ../src/Value/Color.php
332+
333+
-
334+
message: '#^Loose comparison via "\!\=" is not allowed\.$#'
335+
identifier: notEqual.notAllowed
336+
count: 1
337+
path: ../src/Value/Size.php
338+
213339
-
214340
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
215341
identifier: method.notFound
@@ -228,4 +354,16 @@ parameters:
228354
count: 1
229355
path: ../src/Value/ValueList.php
230356

357+
-
358+
message: '#^Dynamic call to static method Sabberworm\\CSS\\Tests\\ParserTest\:\:parsedStructureForFile\(\)\.$#'
359+
identifier: staticMethod.dynamicCall
360+
count: 2
361+
path: ../tests/ParserTest.php
362+
363+
-
364+
message: '#^Loose comparison via "\=\=" is not allowed\.$#'
365+
identifier: equal.notAllowed
366+
count: 11
367+
path: ../tests/ParserTest.php
368+
231369

0 commit comments

Comments
 (0)