You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if ($instanceofTypeWithoutPhpDocsinstanceof ConstantBooleanType) {
54
+
return$ruleErrorBuilder;
55
+
}
56
+
57
+
return$ruleErrorBuilder->tip('Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.');
58
+
};
59
+
47
60
if (!$nodeType->getValue()) {
48
61
return [
49
-
RuleErrorBuilder::message(sprintf(
62
+
$addTip(RuleErrorBuilder::message(sprintf(
50
63
'Strict comparison using %s between %s and %s will always evaluate to false.',
Copy file name to clipboardExpand all lines: tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php
+33Lines changed: 33 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -32,6 +32,7 @@ protected function shouldTreatPhpDocTypesAsCertain(): bool
32
32
publicfunctiontestStrictComparison(): void
33
33
{
34
34
$this->checkAlwaysTrueStrictComparison = true;
35
+
$tipText = 'Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.';
35
36
$this->analyse(
36
37
[__DIR__ . '/data/strict-comparison.php'],
37
38
[
@@ -58,6 +59,7 @@ public function testStrictComparison(): void
58
59
[
59
60
'Strict comparison using === between 1 and array<StrictComparison\Foo>|bool|StrictComparison\Collection will always evaluate to false.',
60
61
19,
62
+
$tipText,
61
63
],
62
64
[
63
65
'Strict comparison using === between true and false will always evaluate to false.',
@@ -110,10 +112,12 @@ public function testStrictComparison(): void
110
112
[
111
113
'Strict comparison using !== between StrictComparison\Node|null and false will always evaluate to true.',
112
114
212,
115
+
$tipText,
113
116
],
114
117
[
115
118
'Strict comparison using !== between StrictComparison\Node|null and false will always evaluate to true.',
116
119
255,
120
+
$tipText,
117
121
],
118
122
[
119
123
'Strict comparison using !== between stdClass and null will always evaluate to true.',
@@ -182,6 +186,7 @@ public function testStrictComparison(): void
182
186
[
183
187
'Strict comparison using === between int<0, 1> and 100 will always evaluate to false.',
184
188
622,
189
+
$tipText,
185
190
],
186
191
[
187
192
'Strict comparison using === between 100 and \'foo\' will always evaluate to false.',
@@ -267,6 +272,7 @@ public function testStrictComparison(): void
$tipText = 'Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.';
270
276
$this->analyse(
271
277
[__DIR__ . '/data/strict-comparison.php'],
272
278
[
@@ -285,6 +291,7 @@ public function testStrictComparisonWithoutAlwaysTrue(): void
285
291
[
286
292
'Strict comparison using === between 1 and array<StrictComparison\Foo>|bool|StrictComparison\Collection will always evaluate to false.',
287
293
19,
294
+
$tipText,
288
295
],
289
296
[
290
297
'Strict comparison using === between true and false will always evaluate to false.',
@@ -377,6 +384,7 @@ public function testStrictComparisonWithoutAlwaysTrue(): void
377
384
[
378
385
'Strict comparison using === between int<0, 1> and 100 will always evaluate to false.',
379
386
622,
387
+
$tipText,
380
388
],
381
389
[
382
390
'Strict comparison using === between 100 and \'foo\' will always evaluate to false.',
@@ -572,6 +580,7 @@ public function testBug7555(): void
572
580
[
573
581
'Strict comparison using === between 2 and 2 will always evaluate to true.',
574
582
11,
583
+
'Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.',
575
584
],
576
585
]);
577
586
}
@@ -693,14 +702,17 @@ public function testBug4242(): void
693
702
publicfunctiontestBug3633(): void
694
703
{
695
704
$this->checkAlwaysTrueStrictComparison = true;
705
+
$tipText = 'Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.';
'Strict comparison using === between int<1, max> and 0 will always evaluate to false.',
933
+
12,
934
+
'Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.',
0 commit comments