Skip to content

Commit b8e797c

Browse files
committed
simplify
1 parent e68e1e4 commit b8e797c

File tree

3 files changed

+13
-49
lines changed

3 files changed

+13
-49
lines changed

src/Analyser/MutatingScope.php

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@
139139
use PHPStan\Type\VoidType;
140140
use stdClass;
141141
use Throwable;
142-
use ValueError;
143142
use function abs;
144143
use function array_filter;
145144
use function array_key_exists;
@@ -152,18 +151,17 @@
152151
use function array_values;
153152
use function count;
154153
use function explode;
155-
use function function_exists;
156154
use function get_class;
157155
use function implode;
158156
use function in_array;
159157
use function is_array;
160158
use function is_bool;
161-
use function is_numeric;
162159
use function is_string;
163160
use function ltrim;
164161
use function md5;
162+
use function restore_error_handler;
163+
use function set_error_handler;
165164
use function sprintf;
166-
use function str_increment;
167165
use function str_starts_with;
168166
use function strlen;
169167
use function strtolower;
@@ -1738,37 +1736,24 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
17381736
$varScalars = $varType->getConstantScalarValues();
17391737

17401738
if (count($varScalars) > 0) {
1741-
$newTypes = [];
1739+
$newValues = [];
17421740

1741+
// silence string incrementing deprecation warnings
1742+
set_error_handler(static fn (): bool => true);
17431743
foreach ($varScalars as $varValue) {
1744-
// until PHP 8.5 it was valid to increment/decrement an empty string.
1745-
// see https://github.com/php/php-src/issues/19597
17461744
if ($node instanceof Expr\PreInc) {
1747-
if ($varValue === '') {
1748-
$varValue = '1';
1749-
} elseif (
1750-
is_string($varValue)
1751-
&& !is_numeric($varValue)
1752-
&& function_exists('str_increment')
1753-
) {
1754-
try {
1755-
$varValue = str_increment($varValue);
1756-
} catch (ValueError) {
1757-
return new ErrorType();
1758-
}
1759-
} elseif (!is_bool($varValue)) {
1745+
if (!is_bool($varValue)) {
17601746
++$varValue;
17611747
}
17621748
} else {
1763-
if ($varValue === '') {
1764-
$varValue = -1;
1765-
} elseif (is_numeric($varValue)) {
1766-
--$varValue;
1767-
}
1749+
--$varValue;
17681750
}
17691751

1770-
$newTypes[] = $this->getTypeFromValue($varValue);
1752+
$newValues[] = $varValue;
17711753
}
1754+
restore_error_handler();
1755+
1756+
$newTypes = array_map(fn ($value): Type => $this->getTypeFromValue($value), $newValues);
17721757
return TypeCombinator::union(...$newTypes);
17731758
} elseif ($varType->isString()->yes()) {
17741759
if ($varType->isLiteralString()->yes()) {

tests/PHPStan/Analyser/nsrt/bug-13481-before-php83.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/PHPStan/Analyser/nsrt/bug-13481-php83.php renamed to tests/PHPStan/Analyser/nsrt/bug-13481.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<?php // lint >= 8.3
1+
<?php
22

3-
namespace bug13481Php83;
3+
namespace bug13481;
44

55
use function PHPStan\Testing\assertType;
66
use function str_increment;

0 commit comments

Comments
 (0)