Skip to content

Commit 5582803

Browse files
ruudkondrejmirtes
authored andcommitted
Allow toggling treatPhpDocTypesAsCertain tip
Fixes phpstan/phpstan#11689
1 parent 7a6a0fa commit 5582803

File tree

48 files changed

+174
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+174
-11
lines changed

conf/config.level4.neon

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ services:
6767
checkAlwaysTrueInstanceof: %checkAlwaysTrueInstanceof%
6868
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
6969
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
70+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
7071
tags:
7172
- phpstan.rules.rule
7273

@@ -76,6 +77,7 @@ services:
7677
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
7778
bleedingEdge: %featureToggles.bleedingEdge%
7879
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
80+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
7981
tags:
8082
- phpstan.rules.rule
8183

@@ -85,6 +87,7 @@ services:
8587
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
8688
bleedingEdge: %featureToggles.bleedingEdge%
8789
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
90+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
8891
tags:
8992
- phpstan.rules.rule
9093

@@ -93,6 +96,7 @@ services:
9396
arguments:
9497
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
9598
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
99+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
96100
tags:
97101
- phpstan.rules.rule
98102

@@ -149,6 +153,7 @@ services:
149153
class: PHPStan\Rules\Comparison\DoWhileLoopConstantConditionRule
150154
arguments:
151155
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
156+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
152157
tags:
153158
- phpstan.rules.rule
154159

@@ -157,13 +162,15 @@ services:
157162
arguments:
158163
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
159164
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
165+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
160166
tags:
161167
- phpstan.rules.rule
162168

163169
-
164170
class: PHPStan\Rules\Comparison\IfConstantConditionRule
165171
arguments:
166172
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
173+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
167174
tags:
168175
- phpstan.rules.rule
169176

@@ -173,6 +180,7 @@ services:
173180
checkAlwaysTrueCheckTypeFunctionCall: %checkAlwaysTrueCheckTypeFunctionCall%
174181
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
175182
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
183+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
176184
tags:
177185
- phpstan.rules.rule
178186

@@ -182,6 +190,7 @@ services:
182190
checkAlwaysTrueCheckTypeFunctionCall: %checkAlwaysTrueCheckTypeFunctionCall%
183191
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
184192
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
193+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
185194
tags:
186195
- phpstan.rules.rule
187196

@@ -191,6 +200,7 @@ services:
191200
checkAlwaysTrueCheckTypeFunctionCall: %checkAlwaysTrueCheckTypeFunctionCall%
192201
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
193202
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
203+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
194204
tags:
195205
- phpstan.rules.rule
196206

@@ -199,6 +209,7 @@ services:
199209
arguments:
200210
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
201211
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
212+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
202213

203214
-
204215
class: PHPStan\Rules\DeadCode\BetterNoopRule
@@ -217,6 +228,7 @@ services:
217228
class: PHPStan\Rules\Comparison\NumberComparisonOperatorsConstantConditionRule
218229
arguments:
219230
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
231+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
220232
tags:
221233
- phpstan.rules.rule
222234

@@ -226,6 +238,7 @@ services:
226238
checkAlwaysTrueStrictComparison: %checkAlwaysTrueStrictComparison%
227239
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
228240
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
241+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
229242
tags:
230243
- phpstan.rules.rule
231244

@@ -235,11 +248,13 @@ services:
235248
checkAlwaysTrueLooseComparison: %checkAlwaysTrueLooseComparison%
236249
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
237250
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
251+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
238252

239253
-
240254
class: PHPStan\Rules\Comparison\TernaryOperatorConstantConditionRule
241255
arguments:
242256
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
257+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
243258
tags:
244259
- phpstan.rules.rule
245260

@@ -248,6 +263,7 @@ services:
248263
arguments:
249264
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
250265
disable: %featureToggles.disableUnreachableBranchesRules%
266+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
251267
tags:
252268
- phpstan.rules.rule
253269

@@ -256,20 +272,23 @@ services:
256272
arguments:
257273
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
258274
disable: %featureToggles.disableUnreachableBranchesRules%
275+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
259276
tags:
260277
- phpstan.rules.rule
261278

262279
-
263280
class: PHPStan\Rules\Comparison\WhileLoopAlwaysFalseConditionRule
264281
arguments:
265282
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
283+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
266284
tags:
267285
- phpstan.rules.rule
268286

269287
-
270288
class: PHPStan\Rules\Comparison\WhileLoopAlwaysTrueConditionRule
271289
arguments:
272290
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
291+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
273292
tags:
274293
- phpstan.rules.rule
275294

conf/config.level5.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ services:
3434
class: PHPStan\Rules\Functions\ArrayFilterRule
3535
arguments:
3636
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
37+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
3738

3839
-
3940
class: PHPStan\Rules\Functions\ArrayValuesRule
4041
arguments:
4142
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
43+
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
4244

4345
-
4446
class: PHPStan\Rules\Functions\CallUserFuncRule

conf/config.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ parameters:
161161
treatPhpDocTypesAsCertain: true
162162
usePathConstantsAsConstantString: false
163163
rememberPossiblyImpureFunctionValues: true
164+
tips:
165+
treatPhpDocTypesAsCertain: true
164166
tipsOfTheDay: true
165167
reportMagicMethods: false
166168
reportMagicProperties: false

conf/parametersSchema.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ parametersSchema:
129129
deprecationRulesInstalled: bool()
130130
inferPrivatePropertyTypeFromConstructor: bool()
131131

132+
tips: structure([
133+
treatPhpDocTypesAsCertain: bool()
134+
])
132135
tipsOfTheDay: bool()
133136
reportMaybes: bool()
134137
reportMaybesInMethodSignatures: bool()

src/Rules/Classes/ImpossibleInstanceOfRule.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function __construct(
2525
private bool $checkAlwaysTrueInstanceof,
2626
private bool $treatPhpDocTypesAsCertain,
2727
private bool $reportAlwaysTrueInLastCondition,
28+
private bool $treatPhpDocTypesAsCertainTip,
2829
)
2930
{
3031
}
@@ -71,6 +72,10 @@ public function processNode(Node $node, Scope $scope): array
7172
return $ruleErrorBuilder;
7273
}
7374

75+
if (!$this->treatPhpDocTypesAsCertainTip) {
76+
return $ruleErrorBuilder;
77+
}
78+
7479
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
7580
};
7681

src/Rules/Comparison/BooleanAndConstantConditionRule.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function __construct(
2323
private bool $treatPhpDocTypesAsCertain,
2424
private bool $bleedingEdge,
2525
private bool $reportAlwaysTrueInLastCondition,
26+
private bool $treatPhpDocTypesAsCertainTip,
2627
)
2728
{
2829
}
@@ -52,6 +53,9 @@ public function processNode(
5253
if ($booleanNativeType instanceof ConstantBooleanType) {
5354
return $ruleErrorBuilder;
5455
}
56+
if (!$this->treatPhpDocTypesAsCertainTip) {
57+
return $ruleErrorBuilder;
58+
}
5559

5660
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
5761
};
@@ -90,6 +94,9 @@ public function processNode(
9094
if ($booleanNativeType instanceof ConstantBooleanType) {
9195
return $ruleErrorBuilder;
9296
}
97+
if (!$this->treatPhpDocTypesAsCertainTip) {
98+
return $ruleErrorBuilder;
99+
}
93100

94101
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
95102
};
@@ -122,6 +129,9 @@ public function processNode(
122129
if ($booleanNativeType instanceof ConstantBooleanType) {
123130
return $ruleErrorBuilder;
124131
}
132+
if (!$this->treatPhpDocTypesAsCertainTip) {
133+
return $ruleErrorBuilder;
134+
}
125135

126136
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
127137
};

src/Rules/Comparison/BooleanNotConstantConditionRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function __construct(
2020
private ConstantConditionRuleHelper $helper,
2121
private bool $treatPhpDocTypesAsCertain,
2222
private bool $reportAlwaysTrueInLastCondition,
23+
private bool $treatPhpDocTypesAsCertainTip,
2324
)
2425
{
2526
}
@@ -45,6 +46,9 @@ public function processNode(
4546
if ($booleanNativeType instanceof ConstantBooleanType) {
4647
return $ruleErrorBuilder;
4748
}
49+
if (!$this->treatPhpDocTypesAsCertainTip) {
50+
return $ruleErrorBuilder;
51+
}
4852

4953
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
5054
};

src/Rules/Comparison/BooleanOrConstantConditionRule.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function __construct(
2323
private bool $treatPhpDocTypesAsCertain,
2424
private bool $bleedingEdge,
2525
private bool $reportAlwaysTrueInLastCondition,
26+
private bool $treatPhpDocTypesAsCertainTip,
2627
)
2728
{
2829
}
@@ -52,6 +53,9 @@ public function processNode(
5253
if ($booleanNativeType instanceof ConstantBooleanType) {
5354
return $ruleErrorBuilder;
5455
}
56+
if (!$this->treatPhpDocTypesAsCertainTip) {
57+
return $ruleErrorBuilder;
58+
}
5559

5660
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
5761
};
@@ -90,6 +94,9 @@ public function processNode(
9094
if ($booleanNativeType instanceof ConstantBooleanType) {
9195
return $ruleErrorBuilder;
9296
}
97+
if (!$this->treatPhpDocTypesAsCertainTip) {
98+
return $ruleErrorBuilder;
99+
}
93100

94101
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
95102
};
@@ -122,6 +129,9 @@ public function processNode(
122129
if ($booleanNativeType instanceof ConstantBooleanType) {
123130
return $ruleErrorBuilder;
124131
}
132+
if (!$this->treatPhpDocTypesAsCertainTip) {
133+
return $ruleErrorBuilder;
134+
}
125135

126136
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
127137
};

src/Rules/Comparison/ConstantLooseComparisonRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function __construct(
2121
private bool $checkAlwaysTrueLooseComparison,
2222
private bool $treatPhpDocTypesAsCertain,
2323
private bool $reportAlwaysTrueInLastCondition,
24+
private bool $treatPhpDocTypesAsCertainTip,
2425
)
2526
{
2627
}
@@ -50,6 +51,9 @@ public function processNode(Node $node, Scope $scope): array
5051
if ($instanceofTypeWithoutPhpDocs instanceof ConstantBooleanType) {
5152
return $ruleErrorBuilder;
5253
}
54+
if (!$this->treatPhpDocTypesAsCertainTip) {
55+
return $ruleErrorBuilder;
56+
}
5357

5458
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
5559
};

src/Rules/Comparison/DoWhileLoopConstantConditionRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ final class DoWhileLoopConstantConditionRule implements Rule
2222
public function __construct(
2323
private ConstantConditionRuleHelper $helper,
2424
private bool $treatPhpDocTypesAsCertain,
25+
private bool $treatPhpDocTypesAsCertainTip,
2526
)
2627
{
2728
}
@@ -70,6 +71,9 @@ public function processNode(Node $node, Scope $scope): array
7071
if ($booleanNativeType instanceof ConstantBooleanType) {
7172
return $ruleErrorBuilder;
7273
}
74+
if (!$this->treatPhpDocTypesAsCertainTip) {
75+
return $ruleErrorBuilder;
76+
}
7377

7478
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
7579
};

src/Rules/Comparison/ElseIfConstantConditionRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function __construct(
2020
private ConstantConditionRuleHelper $helper,
2121
private bool $treatPhpDocTypesAsCertain,
2222
private bool $reportAlwaysTrueInLastCondition,
23+
private bool $treatPhpDocTypesAsCertainTip,
2324
)
2425
{
2526
}
@@ -45,6 +46,9 @@ public function processNode(
4546
if ($booleanNativeType instanceof ConstantBooleanType) {
4647
return $ruleErrorBuilder;
4748
}
49+
if (!$this->treatPhpDocTypesAsCertainTip) {
50+
return $ruleErrorBuilder;
51+
}
4852

4953
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
5054
};

src/Rules/Comparison/IfConstantConditionRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ final class IfConstantConditionRule implements Rule
1818
public function __construct(
1919
private ConstantConditionRuleHelper $helper,
2020
private bool $treatPhpDocTypesAsCertain,
21+
private bool $treatPhpDocTypesAsCertainTip,
2122
)
2223
{
2324
}
@@ -43,6 +44,9 @@ public function processNode(
4344
if ($booleanNativeType instanceof ConstantBooleanType) {
4445
return $ruleErrorBuilder;
4546
}
47+
if (!$this->treatPhpDocTypesAsCertainTip) {
48+
return $ruleErrorBuilder;
49+
}
4650

4751
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
4852
};

src/Rules/Comparison/ImpossibleCheckTypeFunctionCallRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function __construct(
2121
private bool $checkAlwaysTrueCheckTypeFunctionCall,
2222
private bool $treatPhpDocTypesAsCertain,
2323
private bool $reportAlwaysTrueInLastCondition,
24+
private bool $treatPhpDocTypesAsCertainTip,
2425
)
2526
{
2627
}
@@ -54,6 +55,9 @@ public function processNode(Node $node, Scope $scope): array
5455
if ($isAlways !== null) {
5556
return $ruleErrorBuilder;
5657
}
58+
if (!$this->treatPhpDocTypesAsCertainTip) {
59+
return $ruleErrorBuilder;
60+
}
5761

5862
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
5963
};

0 commit comments

Comments
 (0)