Skip to content

Commit a134fea

Browse files
committed
Fix
1 parent f6e1c1c commit a134fea

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

src/Analyser/MutatingScope.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
use function in_array;
158158
use function is_array;
159159
use function is_bool;
160+
use function is_numeric;
160161
use function is_string;
161162
use function ltrim;
162163
use function md5;
@@ -1768,7 +1769,7 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
17681769
if ($node instanceof Expr\PreInc) {
17691770
if ($varValue === '') {
17701771
$varValue = '1';
1771-
} elseif (is_string($varValue)) {
1772+
} elseif (is_string($varValue) && !is_numeric($varValue)) {
17721773
try {
17731774
$varValue = str_increment($varValue);
17741775
} catch (ValueError) {
@@ -1780,13 +1781,13 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
17801781
} else {
17811782
if ($varValue === '') {
17821783
$varValue = -1;
1783-
} elseif (is_string($varValue)) {
1784+
} elseif (is_string($varValue) && !is_numeric($varValue)) {
17841785
try {
17851786
$varValue = str_decrement($varValue);
17861787
} catch (ValueError) {
17871788
return new NeverType();
17881789
}
1789-
} elseif (!is_bool($varValue)) {
1790+
} elseif (is_numeric($varValue)) {
17901791
--$varValue;
17911792
}
17921793
}

tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2992,15 +2992,15 @@ public static function dataBinaryOperations(): array
29922992
'++$fooString',
29932993
],
29942994
[
2995-
'\'foo\'',
2995+
'\'fon\'',
29962996
'--$fooString',
29972997
],
29982998
[
29992999
'\'fop\'',
30003000
'$incrementedFooString',
30013001
],
30023002
[
3003-
'\'foo\'',
3003+
'\'fon\'',
30043004
'$decrementedFooString',
30053005
],
30063006
[

tests/PHPStan/Analyser/nsrt/pre-dec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ function doFoo2() {
1919
function doFooBar() {
2020
$s = 'abc';
2121
--$s;
22-
assertType("'abc'", $s);
22+
assertType("'abb'", $s);
2323
}

tests/PHPStan/Analyser/nsrt/str_decrement.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
function foo(string $s): void
1313
{
1414
assertType('non-empty-string', str_decrement($s));
15-
assertType('*ERROR*', str_decrement(''));
16-
assertType('*ERROR*', str_decrement('0'));
17-
assertType('*ERROR*', str_decrement('0.0'));
18-
assertType('*ERROR*', str_decrement('1.0'));
19-
assertType('*ERROR*', str_decrement('a'));
20-
assertType('*ERROR*', str_decrement('A'));
21-
assertType('*ERROR*', str_decrement('='));
22-
assertType('*ERROR*', str_decrement(''));
15+
assertType('*NEVER*', str_decrement(''));
16+
assertType('*NEVER*', str_decrement('0'));
17+
assertType('*NEVER*', str_decrement('0.0'));
18+
assertType('*NEVER*', str_decrement('1.0'));
19+
assertType('*NEVER*', str_decrement('a'));
20+
assertType('*NEVER*', str_decrement('A'));
21+
assertType('*NEVER*', str_decrement('='));
22+
assertType('*NEVER*', str_decrement(''));
2323
assertType("'0'", str_decrement('1'));
2424
assertType("'8'", str_decrement('9'));
2525
assertType("'9'", str_decrement('10'));

tests/PHPStan/Analyser/nsrt/str_increment.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
function foo(string $s)
1313
{
1414
assertType('non-falsy-string', str_increment($s));
15-
assertType('*ERROR*', str_increment(''));
16-
assertType('*ERROR*', str_increment('='));
17-
assertType('*ERROR*', str_increment('0.0'));
18-
assertType('*ERROR*', str_increment('1.0'));
19-
assertType('*ERROR*', str_increment(''));
15+
assertType('*NEVER*', str_increment(''));
16+
assertType('*NEVER*', str_increment('='));
17+
assertType('*NEVER*', str_increment('0.0'));
18+
assertType('*NEVER*', str_increment('1.0'));
19+
assertType('*NEVER*', str_increment(''));
2020
assertType("'1'", str_increment('0'));
2121
assertType("'2'", str_increment('1'));
2222
assertType("'b'", str_increment('a'));

0 commit comments

Comments
 (0)