Skip to content

Commit bea5772

Browse files
committed
[BE] Improve error wording
1 parent 5b34cdb commit bea5772

10 files changed

+9
-333
lines changed

changelog-2.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ Bleeding edge (TODO move to other sections)
5151
* Report `instanceof` of classes not covered by backward compatibility promise (https://github.com/phpstan/phpstan-src/commit/ff4d02d62a7a2e2c4d928d48d31d49246dba7139)
5252
* Report `instanceof` of classes covered by backward compatibility promise but where the assumption might change (https://github.com/phpstan/phpstan-src/commit/996bc69fa977aa64f601bd82b8a0ae39be0cbeef)
5353
* Add `@readonly` rule that disallows default values ([#1391](https://github.com/phpstan/phpstan-src/pull/1391)), thanks @herndlm!
54-
* Improve error wording of the NonexistentOffset, BooleanAndConstantConditionRule, and BooleanOrConstantConditionRule ([#1882](https://github.com/phpstan/phpstan-src/pull/1882)), thanks @VincentLanglet!
5554
* MissingMagicSerializationMethodsRule ([#1711](https://github.com/phpstan/phpstan-src/pull/1711)), #7482, thanks @staabm!
5655
* Stub files validation - detect duplicate classes and functions (https://github.com/phpstan/phpstan-src/commit/ddf8d5c3859c2c75c20f525a0e2ca8b99032373a, https://github.com/phpstan/phpstan-src/commit/17e4b74335e5235d7cd6708eb687a774a0eeead4)
5756
* Change `curl_setopt` function signature based on 2nd arg ([#1719](https://github.com/phpstan/phpstan-src/pull/1719)), thanks @staabm!
@@ -141,6 +140,7 @@ Improvements 🔧
141140
* MethodSignatureRule - look at abstract trait method (https://github.com/phpstan/phpstan-src/commit/5fd8cee591ce1b07daa5f98a1ddcdfc723f1b5eb)
142141
* OverridingMethodRule - include template types in prototype declaring class description (https://github.com/phpstan/phpstan-src/commit/ca2c66cc4dff59ba44d52b82cb9e0aa3256240f3)
143142
* Detect overriding `@final` method in OverridingMethodRule, #9135
143+
* Improve error wording of the NonexistentOffset, BooleanAndConstantConditionRule, and BooleanOrConstantConditionRule ([#1882](https://github.com/phpstan/phpstan-src/pull/1882)), thanks @VincentLanglet!
144144

145145
Bugfixes 🐛
146146
=====================

conf/config.level4.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ services:
7373
class: PHPStan\Rules\Comparison\BooleanAndConstantConditionRule
7474
arguments:
7575
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
76-
bleedingEdge: %featureToggles.bleedingEdge%
7776
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
7877
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
7978
tags:
@@ -83,7 +82,6 @@ services:
8382
class: PHPStan\Rules\Comparison\BooleanOrConstantConditionRule
8483
arguments:
8584
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
86-
bleedingEdge: %featureToggles.bleedingEdge%
8785
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
8886
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
8987
tags:

conf/config.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,6 @@ services:
884884
class: PHPStan\Rules\Arrays\NonexistentOffsetInArrayDimFetchCheck
885885
arguments:
886886
reportMaybes: %reportMaybes%
887-
bleedingEdge: %featureToggles.bleedingEdge%
888887
reportPossiblyNonexistentGeneralArrayOffset: %reportPossiblyNonexistentGeneralArrayOffset%
889888
reportPossiblyNonexistentConstantArrayOffset: %reportPossiblyNonexistentConstantArrayOffset%
890889

src/Rules/Arrays/NonexistentOffsetInArrayDimFetchCheck.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ final class NonexistentOffsetInArrayDimFetchCheck
2222
public function __construct(
2323
private RuleLevelHelper $ruleLevelHelper,
2424
private bool $reportMaybes,
25-
private bool $bleedingEdge,
2625
private bool $reportPossiblyNonexistentGeneralArrayOffset,
2726
private bool $reportPossiblyNonexistentConstantArrayOffset,
2827
)
@@ -104,15 +103,8 @@ public function check(
104103
}
105104

106105
if ($report) {
107-
if ($this->bleedingEdge || $this->reportPossiblyNonexistentGeneralArrayOffset || $this->reportPossiblyNonexistentConstantArrayOffset) {
108-
return [
109-
RuleErrorBuilder::message(sprintf('Offset %s might not exist on %s.', $dimType->describe(VerbosityLevel::value()), $type->describe(VerbosityLevel::value())))
110-
->identifier('offsetAccess.notFound')
111-
->build(),
112-
];
113-
}
114106
return [
115-
RuleErrorBuilder::message(sprintf('Offset %s does not exist on %s.', $dimType->describe(VerbosityLevel::value()), $type->describe(VerbosityLevel::value())))
107+
RuleErrorBuilder::message(sprintf('Offset %s might not exist on %s.', $dimType->describe(VerbosityLevel::value()), $type->describe(VerbosityLevel::value())))
116108
->identifier('offsetAccess.notFound')
117109
->build(),
118110
];

src/Rules/Comparison/BooleanAndConstantConditionRule.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ final class BooleanAndConstantConditionRule implements Rule
2121
public function __construct(
2222
private ConstantConditionRuleHelper $helper,
2323
private bool $treatPhpDocTypesAsCertain,
24-
private bool $bleedingEdge,
2524
private bool $reportAlwaysTrueInLastCondition,
2625
private bool $treatPhpDocTypesAsCertainTip,
2726
)
@@ -40,7 +39,7 @@ public function processNode(
4039
{
4140
$errors = [];
4241
$originalNode = $node->getOriginalNode();
43-
$nodeText = $this->bleedingEdge ? $originalNode->getOperatorSigil() : '&&';
42+
$nodeText = $originalNode->getOperatorSigil();
4443
$leftType = $this->helper->getBooleanType($scope, $originalNode->left);
4544
$identifierType = $originalNode instanceof Node\Expr\BinaryOp\BooleanAnd ? 'booleanAnd' : 'logicalAnd';
4645
if ($leftType instanceof ConstantBooleanType) {

src/Rules/Comparison/BooleanOrConstantConditionRule.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ final class BooleanOrConstantConditionRule implements Rule
2121
public function __construct(
2222
private ConstantConditionRuleHelper $helper,
2323
private bool $treatPhpDocTypesAsCertain,
24-
private bool $bleedingEdge,
2524
private bool $reportAlwaysTrueInLastCondition,
2625
private bool $treatPhpDocTypesAsCertainTip,
2726
)
@@ -39,7 +38,7 @@ public function processNode(
3938
): array
4039
{
4140
$originalNode = $node->getOriginalNode();
42-
$nodeText = $this->bleedingEdge ? $originalNode->getOperatorSigil() : '||';
41+
$nodeText = $originalNode->getOperatorSigil();
4342
$messages = [];
4443
$leftType = $this->helper->getBooleanType($scope, $originalNode->left);
4544
$identifierType = $originalNode instanceof Node\Expr\BinaryOp\BooleanOr ? 'booleanOr' : 'logicalOr';

tests/PHPStan/Rules/Arrays/ArrayDestructuringRuleTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@
1313
class ArrayDestructuringRuleTest extends RuleTestCase
1414
{
1515

16-
private bool $bleedingEdge = false;
17-
1816
protected function getRule(): Rule
1917
{
2018
$ruleLevelHelper = new RuleLevelHelper($this->createReflectionProvider(), true, false, true, false, false, false);
2119

2220
return new ArrayDestructuringRule(
2321
$ruleLevelHelper,
24-
new NonexistentOffsetInArrayDimFetchCheck($ruleLevelHelper, true, $this->bleedingEdge, false, false),
22+
new NonexistentOffsetInArrayDimFetchCheck($ruleLevelHelper, true, false, false),
2523
);
2624
}
2725

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

Lines changed: 4 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class NonexistentOffsetInArrayDimFetchRuleTest extends RuleTestCase
1717

1818
private bool $checkImplicitMixed = false;
1919

20-
private bool $bleedingEdge = false;
21-
2220
private bool $reportPossiblyNonexistentGeneralArrayOffset = false;
2321

2422
private bool $reportPossiblyNonexistentConstantArrayOffset = false;
@@ -29,154 +27,13 @@ protected function getRule(): Rule
2927

3028
return new NonexistentOffsetInArrayDimFetchRule(
3129
$ruleLevelHelper,
32-
new NonexistentOffsetInArrayDimFetchCheck($ruleLevelHelper, true, $this->bleedingEdge, $this->reportPossiblyNonexistentGeneralArrayOffset, $this->reportPossiblyNonexistentConstantArrayOffset),
30+
new NonexistentOffsetInArrayDimFetchCheck($ruleLevelHelper, true, $this->reportPossiblyNonexistentGeneralArrayOffset, $this->reportPossiblyNonexistentConstantArrayOffset),
3331
true,
3432
);
3533
}
3634

3735
public function testRule(): void
3836
{
39-
$this->analyse([__DIR__ . '/data/nonexistent-offset.php'], [
40-
[
41-
'Offset \'b\' does not exist on array{a: stdClass, 0: 2}.',
42-
17,
43-
],
44-
[
45-
'Offset 1 does not exist on array{a: stdClass, 0: 2}.',
46-
18,
47-
],
48-
[
49-
'Offset \'a\' does not exist on array{b: 1}.',
50-
55,
51-
],
52-
[
53-
'Access to offset \'bar\' on an unknown class NonexistentOffset\Bar.',
54-
101,
55-
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
56-
],
57-
[
58-
'Access to an offset on an unknown class NonexistentOffset\Bar.',
59-
102,
60-
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
61-
],
62-
[
63-
'Offset 0 does not exist on array<string, string>.',
64-
111,
65-
],
66-
[
67-
'Offset \'0\' does not exist on array<string, string>.',
68-
112,
69-
],
70-
[
71-
'Offset int does not exist on array<string, string>.',
72-
114,
73-
],
74-
[
75-
'Offset \'test\' does not exist on null.',
76-
126,
77-
],
78-
[
79-
'Cannot access offset 42 on int.',
80-
142,
81-
],
82-
[
83-
'Cannot access offset 42 on float.',
84-
143,
85-
],
86-
[
87-
'Cannot access offset 42 on bool.',
88-
144,
89-
],
90-
[
91-
'Cannot access offset 42 on resource.',
92-
145,
93-
],
94-
[
95-
'Offset \'c\' does not exist on array{c: false}|array{c: true}|array{e: true}.',
96-
171,
97-
],
98-
[
99-
'Offset int does not exist on array{}|array{1: 1, 2: 2}|array{3: 3, 4: 4}.',
100-
190,
101-
],
102-
[
103-
'Offset int does not exist on array{}|array{1: 1, 2: 2}|array{3: 3, 4: 4}.',
104-
193,
105-
],
106-
[
107-
'Offset \'b\' does not exist on array{a: \'blabla\'}.',
108-
225,
109-
],
110-
[
111-
'Offset \'b\' does not exist on array{a: \'blabla\'}.',
112-
228,
113-
],
114-
[
115-
'Cannot access offset \'a\' on Closure(): void.',
116-
253,
117-
],
118-
[
119-
'Cannot access offset \'a\' on array{a: 1, b: 1}|(Closure(): void).',
120-
258,
121-
],
122-
[
123-
'Offset null does not exist on array<int, string>.',
124-
310,
125-
],
126-
[
127-
'Offset int does not exist on array<string, string>.',
128-
312,
129-
],
130-
[
131-
'Offset \'baz\' does not exist on array{bar: 1, baz?: 2}.',
132-
344,
133-
],
134-
[
135-
'Offset \'foo\' does not exist on ArrayAccess<int, stdClass>.',
136-
411,
137-
],
138-
[
139-
'Cannot access offset \'foo\' on stdClass.',
140-
423,
141-
],
142-
[
143-
'Cannot access offset \'foo\' on true.',
144-
426,
145-
],
146-
[
147-
'Cannot access offset \'foo\' on false.',
148-
429,
149-
],
150-
[
151-
'Cannot access offset \'foo\' on resource.',
152-
433,
153-
],
154-
[
155-
'Cannot access offset \'foo\' on 42.',
156-
436,
157-
],
158-
[
159-
'Cannot access offset \'foo\' on 4.141.',
160-
439,
161-
],
162-
[
163-
'Cannot access offset \'foo\' on array|int.',
164-
443,
165-
],
166-
[
167-
'Offset \'feature_pretty…\' does not exist on array{version: non-falsy-string, commit: string|null, pretty_version: string|null, feature_version: non-falsy-string, feature_pretty_version?: string|null}.',
168-
504,
169-
],
170-
[
171-
"Cannot access offset 'foo' on bool.",
172-
517,
173-
],
174-
]);
175-
}
176-
177-
public function testRuleBleedingEdge(): void
178-
{
179-
$this->bleedingEdge = true;
18037
$this->analyse([__DIR__ . '/data/nonexistent-offset.php'], [
18138
[
18239
'Offset \'b\' does not exist on array{a: stdClass, 0: 2}.',
@@ -327,11 +184,11 @@ public function testStrings(): void
327184
13,
328185
],
329186
[
330-
'Offset \'foo\' does not exist on array|string.',
187+
'Offset \'foo\' might not exist on array|string.',
331188
24,
332189
],
333190
[
334-
'Offset 12.34 does not exist on array|string.',
191+
'Offset 12.34 might not exist on array|string.',
335192
28,
336193
],
337194
]);
@@ -531,7 +388,7 @@ public function testBug7000(): void
531388
{
532389
$this->analyse([__DIR__ . '/data/bug-7000.php'], [
533390
[
534-
"Offset 'require'|'require-dev' does not exist on array{require?: array<string, string>, require-dev?: array<string, string>}.",
391+
"Offset 'require'|'require-dev' might not exist on array{require?: array<string, string>, require-dev?: array<string, string>}.",
535392
16,
536393
],
537394
]);
@@ -692,7 +549,6 @@ public function testBug6243(): void
692549

693550
public function testBug8356(): void
694551
{
695-
$this->bleedingEdge = true;
696552
$this->analyse([__DIR__ . '/data/bug-8356.php'], [
697553
[
698554
"Offset 'x' might not exist on array|string.",

0 commit comments

Comments
 (0)