Skip to content

Commit 2e11a47

Browse files
committed
Update typhoon/type, change intRangeT() parsing
1 parent 4f267e8 commit 2e11a47

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

composer.lock

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

src/Internal/ContextualParser.php

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
use Typhoon\PHPStanTypeParser\Context;
2828
use Typhoon\PHPStanTypeParser\CustomParser;
2929
use Typhoon\Type;
30-
use Typhoon\Type\ArrayDefaultT;
30+
use Typhoon\Type\ArrayBareT;
3131
use Typhoon\Type\ArrayT;
3232
use Typhoon\Type\CallableT;
3333
use Typhoon\Type\ConstantT;
34-
use Typhoon\Type\IterableDefaultT;
34+
use Typhoon\Type\IterableBareT;
3535
use Typhoon\Type\IterableT;
3636
use Typhoon\Type\ListT;
3737
use Typhoon\Type\Parameter;
@@ -232,8 +232,8 @@ private function int(array $genericNodes): Type
232232
return match (\count($genericNodes)) {
233233
0 => intT,
234234
2 => intRangeT(
235-
min: self::intRangeLimit($genericNodes[0], 'min'),
236-
max: self::intRangeLimit($genericNodes[1], 'max'),
235+
min: self::intRangeLimit($genericNodes[0]),
236+
max: self::intRangeLimit($genericNodes[1]),
237237
),
238238
default => throw new \LogicException(\sprintf(
239239
'Int range type should have 2 type arguments, got %d',
@@ -242,22 +242,16 @@ private function int(array $genericNodes): Type
242242
};
243243
}
244244

245-
/**
246-
* @param 'min'|'max' $name
247-
*/
248-
private function intRangeLimit(TypeNode $type, string $name): ?int
245+
private function intRangeLimit(TypeNode $type): int
249246
{
250247
$string = (string) $type;
251248

252-
if ($string === $name) {
253-
return null;
254-
}
255-
256-
if (is_numeric($string) && !str_contains($string, '.')) {
257-
return (int) $string;
258-
}
259-
260-
throw new \LogicException();
249+
return match (true) {
250+
$string === 'min' => PHP_INT_MIN,
251+
$string === 'max' => PHP_INT_MAX,
252+
preg_match('/^-?\d+$/D', $string) === 1 => (int) $string,
253+
default => throw new \LogicException(),
254+
};
261255
}
262256

263257
/**
@@ -312,7 +306,7 @@ private function list(array $templateArguments, bool $isNonEmpty = false): ListT
312306
/**
313307
* @param list<Type> $templateArguments
314308
*/
315-
private function array(array $templateArguments, bool $isNonEmpty = false): ArrayDefaultT|ArrayT
309+
private function array(array $templateArguments, bool $isNonEmpty = false): ArrayBareT|ArrayT
316310
{
317311
return match ($number = \count($templateArguments)) {
318312
0 => $isNonEmpty ? new ArrayT(isNonEmpty: true) : arrayT,
@@ -325,7 +319,7 @@ private function array(array $templateArguments, bool $isNonEmpty = false): Arra
325319
/**
326320
* @param list<Type> $templateArguments
327321
*/
328-
private function iterable(array $templateArguments): IterableDefaultT|IterableT
322+
private function iterable(array $templateArguments): IterableBareT|IterableT
329323
{
330324
return match ($number = \count($templateArguments)) {
331325
0 => iterableT,

0 commit comments

Comments
 (0)