Skip to content

Commit e4c5865

Browse files
committed
Install symfony/polyfill-php83
1 parent c9b031e commit e4c5865

File tree

6 files changed

+114
-79
lines changed

6 files changed

+114
-79
lines changed

compiler/build/scoper.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
'../../vendor/phpstan/php-8-stubs/stubs',
1919
'../../vendor/symfony/polyfill-php80',
2020
'../../vendor/symfony/polyfill-php81',
21+
'../../vendor/symfony/polyfill-php83',
2122
'../../vendor/symfony/polyfill-mbstring',
2223
'../../vendor/symfony/polyfill-intl-normalizer',
2324
'../../vendor/symfony/polyfill-intl-grapheme',

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"symfony/polyfill-mbstring": "^1.23",
4747
"symfony/polyfill-php80": "^1.23",
4848
"symfony/polyfill-php81": "^1.27",
49+
"symfony/polyfill-php83": "^1.33",
4950
"symfony/process": "^5.4.3",
5051
"symfony/service-contracts": "^2.5.0",
5152
"symfony/string": "^5.4.3"

composer.lock

Lines changed: 82 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Analyser/MutatingScope.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
use PHPStan\Type\VoidType;
140140
use stdClass;
141141
use Throwable;
142+
use ValueError;
142143
use function abs;
143144
use function array_filter;
144145
use function array_key_exists;
@@ -151,17 +152,16 @@
151152
use function array_values;
152153
use function count;
153154
use function explode;
154-
use function function_exists;
155155
use function get_class;
156156
use function implode;
157157
use function in_array;
158158
use function is_array;
159159
use function is_bool;
160-
use function is_numeric;
161160
use function is_string;
162161
use function ltrim;
163162
use function md5;
164163
use function sprintf;
164+
use function str_decrement;
165165
use function str_increment;
166166
use function str_starts_with;
167167
use function strlen;
@@ -1768,19 +1768,25 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
17681768
if ($node instanceof Expr\PreInc) {
17691769
if ($varValue === '') {
17701770
$varValue = '1';
1771-
} elseif (
1772-
is_string($varValue)
1773-
&& !is_numeric($varValue)
1774-
&& function_exists('str_increment')
1775-
) {
1776-
$varValue = str_increment($varValue);
1771+
} elseif (is_string($varValue)) {
1772+
try {
1773+
$varValue = str_increment($varValue);
1774+
} catch (ValueError) {
1775+
return new NeverType();
1776+
}
17771777
} elseif (!is_bool($varValue)) {
17781778
++$varValue;
17791779
}
17801780
} else {
17811781
if ($varValue === '') {
17821782
$varValue = -1;
1783-
} elseif (is_numeric($varValue)) {
1783+
} elseif (is_string($varValue)) {
1784+
try {
1785+
$varValue = str_decrement($varValue);
1786+
} catch (ValueError) {
1787+
return new NeverType();
1788+
}
1789+
} elseif (!is_bool($varValue)) {
17841790
--$varValue;
17851791
}
17861792
}

src/Type/Php/StrIncrementDecrementFunctionReturnTypeExtension.php

Lines changed: 14 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,19 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\DependencyInjection\AutowiredService;
88
use PHPStan\Reflection\FunctionReflection;
9-
use PHPStan\ShouldNotHappenException;
109
use PHPStan\Type\Constant\ConstantStringType;
1110
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
12-
use PHPStan\Type\ErrorType;
11+
use PHPStan\Type\NeverType;
1312
use PHPStan\Type\Type;
1413
use PHPStan\Type\TypeCombinator;
15-
use function chr;
14+
use ValueError;
1615
use function count;
17-
use function function_exists;
18-
use function implode;
1916
use function in_array;
2017
use function is_float;
2118
use function is_int;
22-
use function is_numeric;
2319
use function is_string;
24-
use function ord;
25-
use function preg_match;
20+
use function str_decrement;
2621
use function str_increment;
27-
use function str_split;
28-
use function stripos;
2922

3023
#[AutowiredService]
3124
final class StrIncrementDecrementFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
@@ -61,10 +54,6 @@ public function getTypeFromFunctionCall(
6154
}
6255
$string = (string) $value;
6356

64-
if (preg_match('/\A(?:0|[1-9A-Za-z][0-9A-Za-z]*)+\z/', $string) < 1) {
65-
continue;
66-
}
67-
6857
$result = null;
6958
if ($fnName === 'str_increment') {
7059
$result = $this->increment($string);
@@ -80,77 +69,34 @@ public function getTypeFromFunctionCall(
8069
}
8170

8271
return count($types) === 0
83-
? new ErrorType()
72+
? new NeverType()
8473
: TypeCombinator::union(...$types);
8574
}
8675

87-
private function increment(string $s): string
76+
private function increment(string $s): ?string
8877
{
89-
if (is_numeric($s)) {
90-
$offset = stripos($s, 'e');
91-
if ($offset !== false) {
92-
// Using increment operator would cast the string to float
93-
// Therefore we manually increment it to convert it to an "f"/"F" that doesn't get affected
94-
$c = $s[$offset];
95-
$c++;
96-
$s[$offset] = $c;
97-
$s++;
98-
$s[$offset] = [
99-
'f' => 'e',
100-
'F' => 'E',
101-
'g' => 'f',
102-
'G' => 'F',
103-
][$s[$offset]];
104-
105-
return $s;
106-
}
107-
}
108-
10978
if ($s === '') {
110-
throw new ShouldNotHappenException();
79+
return null;
11180
}
11281

113-
if (function_exists('str_increment')) {
82+
try {
11483
return str_increment($s);
84+
} catch (ValueError) {
85+
return null;
11586
}
116-
117-
return (string) ++$s;
11887
}
11988

12089
private function decrement(string $s): ?string
12190
{
122-
if (in_array($s, ['a', 'A', '0'], true)) {
91+
if ($s === '') {
12392
return null;
12493
}
12594

126-
$decremented = str_split($s, 1);
127-
$position = count($decremented) - 1;
128-
$carry = false;
129-
$map = [
130-
'0' => '9',
131-
'A' => 'Z',
132-
'a' => 'z',
133-
];
134-
do {
135-
$c = $decremented[$position];
136-
if (!in_array($c, ['a', 'A', '0'], true)) {
137-
$carry = false;
138-
$decremented[$position] = chr(ord($c) - 1);
139-
} else {
140-
$carry = true;
141-
$decremented[$position] = $map[$c];
142-
}
143-
} while ($carry && $position-- > 0);
144-
145-
if ($carry || count($decremented) > 1 && $decremented[0] === '0') {
146-
if (count($decremented) === 1) {
147-
return null;
148-
}
149-
150-
unset($decremented[0]);
95+
try {
96+
return str_decrement($s);
97+
} catch (ValueError) {
98+
return null;
15199
}
152-
153-
return implode($decremented);
154100
}
155101

156102
}

tests/PHPStan/Composer/AutoloadFilesTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function testExpectedFiles(): void
6868
'symfony/polyfill-mbstring/bootstrap.php', // afaik polyfills aren't necessary
6969
'symfony/polyfill-php80/bootstrap.php', // afaik polyfills aren't necessary
7070
'symfony/polyfill-php81/bootstrap.php', // afaik polyfills aren't necessary
71+
'symfony/polyfill-php83/bootstrap.php', // afaik polyfills aren't necessary
7172
'symfony/string/Resources/functions.php', // afaik polyfills aren't necessary
7273
];
7374

0 commit comments

Comments
 (0)