Skip to content

Commit f120c3b

Browse files
MartinMystikJonasondrejmirtes
authored andcommitted
Configuration parameters to enable/disable rules
1 parent 6ec8ce7 commit f120c3b

File tree

2 files changed

+240
-48
lines changed

2 files changed

+240
-48
lines changed

Diff for: README.md

+30-5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,25 @@ 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+
uselessCast: false
67+
requireParentConstructorCall: false
68+
disallowedConstructs: false
69+
overwriteVariablesWithLoop: false
70+
closureUsesThis: false
71+
matchingInheritedMethodNames: false
72+
numericOperandsInArithmeticOperators: false
73+
strictCalls: false
74+
switchConditionsMatchingType: false
75+
noVariableVariables: false
76+
```
5877

5978
## Enabling rules one-by-one
6079

@@ -79,13 +98,19 @@ services:
7998

8099
### With extension-installer
81100

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***.
101+
When using `phpstan/extension-installer` you can disable automatic loading of all rules by:
102+
103+
```neon
104+
parameters:
105+
strictRules:
106+
allRules: false
107+
```
83108

84-
For example:
109+
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:
85110

86111
```neon
87112
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.#'
113+
strictRules:
114+
allRules: false
115+
booleansInConditions: true
91116
```

Diff for: rules.neon

+210-43
Original file line numberDiff line numberDiff line change
@@ -14,59 +14,116 @@ parameters:
1414
reportMaybesInPropertyPhpDocTypes: true
1515
featureToggles:
1616
illegalConstructorMethodCall: %featureToggles.bleedingEdge%
17+
strictRules:
18+
allRules: true
19+
booleansInConditions: %strictRules.allRules%
20+
uselessCast: %strictRules.allRules%
21+
requireParentConstructorCall: %strictRules.allRules%
22+
disallowedConstructs: %strictRules.allRules%
23+
overwriteVariablesWithLoop: %strictRules.allRules%
24+
closureUsesThis: %strictRules.allRules%
25+
matchingInheritedMethodNames: %strictRules.allRules%
26+
numericOperandsInArithmeticOperators: %strictRules.allRules%
27+
strictCalls: %strictRules.allRules%
28+
switchConditionsMatchingType: %strictRules.allRules%
29+
noVariableVariables: %strictRules.allRules%
1730

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
31+
parametersSchema:
32+
strictRules: structure([
33+
allRules: bool(),
34+
booleansInConditions: bool()
35+
uselessCast: bool()
36+
requireParentConstructorCall: bool()
37+
disallowedConstructs: bool()
38+
overwriteVariablesWithLoop: bool()
39+
closureUsesThis: bool()
40+
matchingInheritedMethodNames: bool()
41+
numericOperandsInArithmeticOperators: bool()
42+
strictCalls: bool()
43+
switchConditionsMatchingType: bool()
44+
noVariableVariables: bool()
45+
])
5446

5547
conditionalTags:
5648
PHPStan\Rules\DisallowedConstructs\DisallowedLooseComparisonRule:
5749
phpstan.rules.rule: %featureToggles.bleedingEdge%
50+
PHPStan\Rules\BooleansInConditions\BooleanInBooleanAndRule:
51+
phpstan.rules.rule: %strictRules.booleansInConditions%
52+
PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule:
53+
phpstan.rules.rule: %strictRules.booleansInConditions%
54+
PHPStan\Rules\BooleansInConditions\BooleanInBooleanOrRule:
55+
phpstan.rules.rule: %strictRules.booleansInConditions%
56+
PHPStan\Rules\BooleansInConditions\BooleanInElseIfConditionRule:
57+
phpstan.rules.rule: %strictRules.booleansInConditions%
58+
PHPStan\Rules\BooleansInConditions\BooleanInIfConditionRule:
59+
phpstan.rules.rule: %strictRules.booleansInConditions%
60+
PHPStan\Rules\BooleansInConditions\BooleanInTernaryOperatorRule:
61+
phpstan.rules.rule: %strictRules.booleansInConditions%
62+
PHPStan\Rules\Cast\UselessCastRule:
63+
phpstan.rules.rule: %strictRules.uselessCast%
64+
PHPStan\Rules\Classes\RequireParentConstructCallRule:
65+
phpstan.rules.rule: %strictRules.requireParentConstructorCall%
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.overwriteVariablesWithLoop%
76+
PHPStan\Rules\ForLoop\OverwriteVariablesWithForLoopInitRule:
77+
phpstan.rules.rule: %strictRules.overwriteVariablesWithLoop%
78+
PHPStan\Rules\Functions\ClosureUsesThisRule:
79+
phpstan.rules.rule: %strictRules.closureUsesThis%
80+
PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule:
81+
phpstan.rules.rule: %strictRules.matchingInheritedMethodNames%
82+
PHPStan\Rules\Operators\OperandInArithmeticPostDecrementRule:
83+
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
84+
PHPStan\Rules\Operators\OperandInArithmeticPostIncrementRule:
85+
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
86+
PHPStan\Rules\Operators\OperandInArithmeticPreDecrementRule:
87+
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
88+
PHPStan\Rules\Operators\OperandInArithmeticPreIncrementRule:
89+
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
90+
PHPStan\Rules\Operators\OperandsInArithmeticAdditionRule:
91+
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
92+
PHPStan\Rules\Operators\OperandsInArithmeticDivisionRule:
93+
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
94+
PHPStan\Rules\Operators\OperandsInArithmeticExponentiationRule:
95+
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
96+
PHPStan\Rules\Operators\OperandsInArithmeticModuloRule:
97+
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
98+
PHPStan\Rules\Operators\OperandsInArithmeticMultiplicationRule:
99+
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
100+
PHPStan\Rules\Operators\OperandsInArithmeticSubtractionRule:
101+
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
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.switchConditionsMatchingType%
110+
PHPStan\Rules\VariableVariables\VariableMethodCallRule:
111+
phpstan.rules.rule: %strictRules.noVariableVariables%
112+
PHPStan\Rules\VariableVariables\VariableMethodCallableRule:
113+
phpstan.rules.rule: %strictRules.noVariableVariables%
114+
PHPStan\Rules\VariableVariables\VariableStaticMethodCallRule:
115+
phpstan.rules.rule: %strictRules.noVariableVariables%
116+
PHPStan\Rules\VariableVariables\VariableStaticMethodCallableRule:
117+
phpstan.rules.rule: %strictRules.noVariableVariables%
118+
PHPStan\Rules\VariableVariables\VariableStaticPropertyFetchRule:
119+
phpstan.rules.rule: %strictRules.noVariableVariables%
120+
PHPStan\Rules\VariableVariables\VariableVariablesRule:
121+
phpstan.rules.rule: %strictRules.noVariableVariables%
58122

59123
services:
60124
-
61125
class: PHPStan\Rules\BooleansInConditions\BooleanRuleHelper
62126

63-
-
64-
class: PHPStan\Rules\Cast\UselessCastRule
65-
arguments:
66-
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
67-
tags:
68-
- phpstan.rules.rule
69-
70127
-
71128
class: PHPStan\Rules\Operators\OperatorRuleHelper
72129
-
@@ -78,3 +135,113 @@ services:
78135

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

0 commit comments

Comments
 (0)