|
139 | 139 | use PHPStan\Type\VoidType; |
140 | 140 | use stdClass; |
141 | 141 | use Throwable; |
142 | | -use ValueError; |
143 | 142 | use function abs; |
144 | 143 | use function array_filter; |
145 | 144 | use function array_key_exists; |
|
152 | 151 | use function array_values; |
153 | 152 | use function count; |
154 | 153 | use function explode; |
155 | | -use function function_exists; |
156 | 154 | use function get_class; |
157 | 155 | use function implode; |
158 | 156 | use function in_array; |
159 | 157 | use function is_array; |
160 | 158 | use function is_bool; |
161 | | -use function is_numeric; |
162 | 159 | use function is_string; |
163 | 160 | use function ltrim; |
164 | 161 | use function md5; |
| 162 | +use function restore_error_handler; |
| 163 | +use function set_error_handler; |
165 | 164 | use function sprintf; |
166 | | -use function str_increment; |
167 | 165 | use function str_starts_with; |
168 | 166 | use function strlen; |
169 | 167 | use function strtolower; |
@@ -1738,37 +1736,24 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu |
1738 | 1736 | $varScalars = $varType->getConstantScalarValues(); |
1739 | 1737 |
|
1740 | 1738 | if (count($varScalars) > 0) { |
1741 | | - $newTypes = []; |
| 1739 | + $newValues = []; |
1742 | 1740 |
|
| 1741 | + // silence string incrementing deprecation warnings |
| 1742 | + set_error_handler(static fn (): bool => true); |
1743 | 1743 | 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 |
1746 | 1744 | 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)) { |
1760 | 1746 | ++$varValue; |
1761 | 1747 | } |
1762 | 1748 | } else { |
1763 | | - if ($varValue === '') { |
1764 | | - $varValue = -1; |
1765 | | - } elseif (is_numeric($varValue)) { |
1766 | | - --$varValue; |
1767 | | - } |
| 1749 | + --$varValue; |
1768 | 1750 | } |
1769 | 1751 |
|
1770 | | - $newTypes[] = $this->getTypeFromValue($varValue); |
| 1752 | + $newValues[] = $varValue; |
1771 | 1753 | } |
| 1754 | + restore_error_handler(); |
| 1755 | + |
| 1756 | + $newTypes = array_map(fn ($value): Type => $this->getTypeFromValue($value), $newValues); |
1772 | 1757 | return TypeCombinator::union(...$newTypes); |
1773 | 1758 | } elseif ($varType->isString()->yes()) { |
1774 | 1759 | if ($varType->isLiteralString()->yes()) { |
|
0 commit comments