Skip to content

Commit fe0674e

Browse files
Configuration parameters to enable/disable rules
1 parent 6ec8ce7 commit fe0674e

File tree

2 files changed

+236
-41
lines changed

2 files changed

+236
-41
lines changed

README.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,26 @@ includes:
5555
```
5656
</details>
5757

58+
## Disabling rules
59+
60+
You can disable rules using configuration parameters:
61+
62+
```neon
63+
parameters:
64+
strictRules:
65+
booleansInConditions: false
66+
cast: false
67+
classes: false
68+
disallowedConstructs: false
69+
foreachLoop: false
70+
forLoop: false
71+
functions: false
72+
methods: false
73+
operators: false
74+
strictCalls: false
75+
switchConditions: false
76+
variableVariables: false
77+
```
5878

5979
## Enabling rules one-by-one
6080

@@ -79,13 +99,19 @@ services:
7999

80100
### With extension-installer
81101

82-
Unfortunately, by using `phpstan/extension-installer` you can't enable it one by one, ***but you can [ignore specific errors](https://phpstan.org/user-guide/ignoring-errors) instead***.
102+
When using `phpstan/extension-installer` you can disable automatic rules loading by:
103+
104+
```neon
105+
parameters:
106+
strictRules:
107+
enabled: false
108+
```
83109

84-
For example:
110+
Then you can enable individual rules by adding them as services just like without extension-installer (see above) or re-enable them by configuration parameters:
85111

86112
```neon
87113
parameters:
88-
ignoreErrors:
89-
- '#Construct empty\(\) is not allowed. Use more strict comparison.#'
90-
- '#Call to function in_array\(\) requires parameter \#3 to be set.#'
114+
strictRules:
115+
enabled: false
116+
booleansInConditions: true
91117
```

rules.neon

Lines changed: 205 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,47 +14,111 @@ parameters:
1414
reportMaybesInPropertyPhpDocTypes: true
1515
featureToggles:
1616
illegalConstructorMethodCall: %featureToggles.bleedingEdge%
17+
strictRules:
18+
enabled: true
19+
booleansInConditions: %strictRules.enabled%
20+
cast: %strictRules.enabled%
21+
classes: %strictRules.enabled%
22+
disallowedConstructs: %strictRules.enabled%
23+
foreachLoop: %strictRules.enabled%
24+
forLoop: %strictRules.enabled%
25+
functions: %strictRules.enabled%
26+
methods: %strictRules.enabled%
27+
operators: %strictRules.enabled%
28+
strictCalls: %strictRules.enabled%
29+
switchConditions: %strictRules.enabled%
30+
variableVariables: %strictRules.enabled%
1731

18-
rules:
19-
- PHPStan\Rules\BooleansInConditions\BooleanInBooleanAndRule
20-
- PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule
21-
- PHPStan\Rules\BooleansInConditions\BooleanInBooleanOrRule
22-
- PHPStan\Rules\BooleansInConditions\BooleanInElseIfConditionRule
23-
- PHPStan\Rules\BooleansInConditions\BooleanInIfConditionRule
24-
- PHPStan\Rules\BooleansInConditions\BooleanInTernaryOperatorRule
25-
- PHPStan\Rules\Classes\RequireParentConstructCallRule
26-
- PHPStan\Rules\DisallowedConstructs\DisallowedBacktickRule
27-
- PHPStan\Rules\DisallowedConstructs\DisallowedEmptyRule
28-
- PHPStan\Rules\DisallowedConstructs\DisallowedImplicitArrayCreationRule
29-
- PHPStan\Rules\DisallowedConstructs\DisallowedShortTernaryRule
30-
- PHPStan\Rules\ForeachLoop\OverwriteVariablesWithForeachRule
31-
- PHPStan\Rules\ForLoop\OverwriteVariablesWithForLoopInitRule
32-
- PHPStan\Rules\Functions\ClosureUsesThisRule
33-
- PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule
34-
- PHPStan\Rules\Operators\OperandInArithmeticPostDecrementRule
35-
- PHPStan\Rules\Operators\OperandInArithmeticPostIncrementRule
36-
- PHPStan\Rules\Operators\OperandInArithmeticPreDecrementRule
37-
- PHPStan\Rules\Operators\OperandInArithmeticPreIncrementRule
38-
- PHPStan\Rules\Operators\OperandsInArithmeticAdditionRule
39-
- PHPStan\Rules\Operators\OperandsInArithmeticDivisionRule
40-
- PHPStan\Rules\Operators\OperandsInArithmeticExponentiationRule
41-
- PHPStan\Rules\Operators\OperandsInArithmeticModuloRule
42-
- PHPStan\Rules\Operators\OperandsInArithmeticMultiplicationRule
43-
- PHPStan\Rules\Operators\OperandsInArithmeticSubtractionRule
44-
- PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsRule
45-
- PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsCallableRule
46-
- PHPStan\Rules\StrictCalls\StrictFunctionCallsRule
47-
- PHPStan\Rules\SwitchConditions\MatchingTypeInSwitchCaseConditionRule
48-
- PHPStan\Rules\VariableVariables\VariableMethodCallRule
49-
- PHPStan\Rules\VariableVariables\VariableMethodCallableRule
50-
- PHPStan\Rules\VariableVariables\VariableStaticMethodCallRule
51-
- PHPStan\Rules\VariableVariables\VariableStaticMethodCallableRule
52-
- PHPStan\Rules\VariableVariables\VariableStaticPropertyFetchRule
53-
- PHPStan\Rules\VariableVariables\VariableVariablesRule
32+
parametersSchema:
33+
strictRules: structure([
34+
enabled: bool(),
35+
booleansInConditions: bool()
36+
cast: bool()
37+
classes: bool()
38+
disallowedConstructs: bool()
39+
foreachLoop: bool()
40+
forLoop: bool()
41+
functions: bool()
42+
methods: bool()
43+
operators: bool()
44+
strictCalls: bool()
45+
switchConditions: bool()
46+
variableVariables: bool()
47+
])
5448

5549
conditionalTags:
5650
PHPStan\Rules\DisallowedConstructs\DisallowedLooseComparisonRule:
5751
phpstan.rules.rule: %featureToggles.bleedingEdge%
52+
PHPStan\Rules\BooleansInConditions\BooleanInBooleanAndRule:
53+
phpstan.rules.rule: %strictRules.booleansInConditions%
54+
PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule:
55+
phpstan.rules.rule: %strictRules.booleansInConditions%
56+
PHPStan\Rules\BooleansInConditions\BooleanInBooleanOrRule:
57+
phpstan.rules.rule: %strictRules.booleansInConditions%
58+
PHPStan\Rules\BooleansInConditions\BooleanInElseIfConditionRule:
59+
phpstan.rules.rule: %strictRules.booleansInConditions%
60+
PHPStan\Rules\BooleansInConditions\BooleanInIfConditionRule:
61+
phpstan.rules.rule: %strictRules.booleansInConditions%
62+
PHPStan\Rules\BooleansInConditions\BooleanInTernaryOperatorRule:
63+
phpstan.rules.rule: %strictRules.booleansInConditions%
64+
PHPStan\Rules\Classes\RequireParentConstructCallRule:
65+
phpstan.rules.rule: %strictRules.classes%
66+
PHPStan\Rules\DisallowedConstructs\DisallowedBacktickRule:
67+
phpstan.rules.rule: %strictRules.disallowedConstructs%
68+
PHPStan\Rules\DisallowedConstructs\DisallowedEmptyRule:
69+
phpstan.rules.rule: %strictRules.disallowedConstructs%
70+
PHPStan\Rules\DisallowedConstructs\DisallowedImplicitArrayCreationRule:
71+
phpstan.rules.rule: %strictRules.disallowedConstructs%
72+
PHPStan\Rules\DisallowedConstructs\DisallowedShortTernaryRule:
73+
phpstan.rules.rule: %strictRules.disallowedConstructs%
74+
PHPStan\Rules\ForeachLoop\OverwriteVariablesWithForeachRule:
75+
phpstan.rules.rule: %strictRules.foreachLoop%
76+
PHPStan\Rules\ForLoop\OverwriteVariablesWithForLoopInitRule:
77+
phpstan.rules.rule: %strictRules.forLoop%
78+
PHPStan\Rules\Functions\ClosureUsesThisRule:
79+
phpstan.rules.rule: %strictRules.functions%
80+
PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule:
81+
phpstan.rules.rule: %strictRules.methods%
82+
PHPStan\Rules\Operators\OperandInArithmeticPostDecrementRule:
83+
phpstan.rules.rule: %strictRules.operators%
84+
PHPStan\Rules\Operators\OperandInArithmeticPostIncrementRule:
85+
phpstan.rules.rule: %strictRules.operators%
86+
PHPStan\Rules\Operators\OperandInArithmeticPreDecrementRule:
87+
phpstan.rules.rule: %strictRules.operators%
88+
PHPStan\Rules\Operators\OperandInArithmeticPreIncrementRule:
89+
phpstan.rules.rule: %strictRules.operators%
90+
PHPStan\Rules\Operators\OperandsInArithmeticAdditionRule:
91+
phpstan.rules.rule: %strictRules.operators%
92+
PHPStan\Rules\Operators\OperandsInArithmeticDivisionRule:
93+
phpstan.rules.rule: %strictRules.operators%
94+
PHPStan\Rules\Operators\OperandsInArithmeticExponentiationRule:
95+
phpstan.rules.rule: %strictRules.operators%
96+
PHPStan\Rules\Operators\OperandsInArithmeticModuloRule:
97+
phpstan.rules.rule: %strictRules.operators%
98+
PHPStan\Rules\Operators\OperandsInArithmeticMultiplicationRule:
99+
phpstan.rules.rule: %strictRules.operators%
100+
PHPStan\Rules\Operators\OperandsInArithmeticSubtractionRule:
101+
phpstan.rules.rule: %strictRules.operators%
102+
PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsRule:
103+
phpstan.rules.rule: %strictRules.strictCalls%
104+
PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsCallableRule:
105+
phpstan.rules.rule: %strictRules.strictCalls%
106+
PHPStan\Rules\StrictCalls\StrictFunctionCallsRule:
107+
phpstan.rules.rule: %strictRules.strictCalls%
108+
PHPStan\Rules\SwitchConditions\MatchingTypeInSwitchCaseConditionRule:
109+
phpstan.rules.rule: %strictRules.switchConditions%
110+
PHPStan\Rules\VariableVariables\VariableMethodCallRule:
111+
phpstan.rules.rule: %strictRules.variableVariables%
112+
PHPStan\Rules\VariableVariables\VariableMethodCallableRule:
113+
phpstan.rules.rule: %strictRules.variableVariables%
114+
PHPStan\Rules\VariableVariables\VariableStaticMethodCallRule:
115+
phpstan.rules.rule: %strictRules.variableVariables%
116+
PHPStan\Rules\VariableVariables\VariableStaticMethodCallableRule:
117+
phpstan.rules.rule: %strictRules.variableVariables%
118+
PHPStan\Rules\VariableVariables\VariableStaticPropertyFetchRule:
119+
phpstan.rules.rule: %strictRules.variableVariables%
120+
PHPStan\Rules\VariableVariables\VariableVariablesRule:
121+
phpstan.rules.rule: %strictRules.variableVariables%
58122

59123
services:
60124
-
@@ -78,3 +142,108 @@ services:
78142

79143
-
80144
class: PHPStan\Rules\DisallowedConstructs\DisallowedLooseComparisonRule
145+
146+
-
147+
class: PHPStan\Rules\BooleansInConditions\BooleanInBooleanAndRule
148+
149+
-
150+
class: PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule
151+
152+
-
153+
class: PHPStan\Rules\BooleansInConditions\BooleanInBooleanOrRule
154+
155+
-
156+
class: PHPStan\Rules\BooleansInConditions\BooleanInElseIfConditionRule
157+
158+
-
159+
class: PHPStan\Rules\BooleansInConditions\BooleanInIfConditionRule
160+
161+
-
162+
class: PHPStan\Rules\BooleansInConditions\BooleanInTernaryOperatorRule
163+
164+
-
165+
class: PHPStan\Rules\Classes\RequireParentConstructCallRule
166+
167+
-
168+
class: PHPStan\Rules\DisallowedConstructs\DisallowedBacktickRule
169+
170+
-
171+
class: PHPStan\Rules\DisallowedConstructs\DisallowedEmptyRule
172+
173+
-
174+
class: PHPStan\Rules\DisallowedConstructs\DisallowedImplicitArrayCreationRule
175+
176+
-
177+
class: PHPStan\Rules\DisallowedConstructs\DisallowedShortTernaryRule
178+
179+
-
180+
class: PHPStan\Rules\ForeachLoop\OverwriteVariablesWithForeachRule
181+
182+
-
183+
class: PHPStan\Rules\ForLoop\OverwriteVariablesWithForLoopInitRule
184+
185+
-
186+
class: PHPStan\Rules\Functions\ClosureUsesThisRule
187+
188+
-
189+
class: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule
190+
191+
-
192+
class: PHPStan\Rules\Operators\OperandInArithmeticPostDecrementRule
193+
194+
-
195+
class: PHPStan\Rules\Operators\OperandInArithmeticPostIncrementRule
196+
197+
-
198+
class: PHPStan\Rules\Operators\OperandInArithmeticPreDecrementRule
199+
200+
-
201+
class: PHPStan\Rules\Operators\OperandInArithmeticPreIncrementRule
202+
203+
-
204+
class: PHPStan\Rules\Operators\OperandsInArithmeticAdditionRule
205+
206+
-
207+
class: PHPStan\Rules\Operators\OperandsInArithmeticDivisionRule
208+
209+
-
210+
class: PHPStan\Rules\Operators\OperandsInArithmeticExponentiationRule
211+
212+
-
213+
class: PHPStan\Rules\Operators\OperandsInArithmeticModuloRule
214+
215+
-
216+
class: PHPStan\Rules\Operators\OperandsInArithmeticMultiplicationRule
217+
218+
-
219+
class: PHPStan\Rules\Operators\OperandsInArithmeticSubtractionRule
220+
221+
-
222+
class: PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsRule
223+
224+
-
225+
class: PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsCallableRule
226+
227+
-
228+
class: PHPStan\Rules\StrictCalls\StrictFunctionCallsRule
229+
230+
-
231+
class: PHPStan\Rules\SwitchConditions\MatchingTypeInSwitchCaseConditionRule
232+
233+
-
234+
class: PHPStan\Rules\VariableVariables\VariableMethodCallRule
235+
236+
-
237+
class: PHPStan\Rules\VariableVariables\VariableMethodCallableRule
238+
239+
-
240+
class: PHPStan\Rules\VariableVariables\VariableStaticMethodCallRule
241+
242+
-
243+
class: PHPStan\Rules\VariableVariables\VariableStaticMethodCallableRule
244+
245+
-
246+
class: PHPStan\Rules\VariableVariables\VariableStaticPropertyFetchRule
247+
248+
-
249+
class: PHPStan\Rules\VariableVariables\VariableVariablesRule

0 commit comments

Comments
 (0)