Skip to content

Commit f6526bc

Browse files
committed
Make int limits nullable
1 parent 7a05d1a commit f6526bc

File tree

5 files changed

+6
-10
lines changed

5 files changed

+6
-10
lines changed

generator/spec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
// int
3030
single('int', 'int', 'intRange()'),
3131
constr('intValue', 'T', [tpl('T', 'int')], [prop('value', 'T', nativeType: 'int')], 'intRange($value, $value)'),
32-
constr('intRange', 'T', [tpl('T', 'int')], [prop('min', 'int', 'PHP_INT_MIN'), prop('max', 'int', 'PHP_INT_MAX')]),
32+
constr('intRange', 'T', [tpl('T', 'int')], [prop('min', '?int'), prop('max', '?int')]),
3333
single('negativeInt', 'negative-int', 'intRange(max: -1)'),
3434
single('nonPositiveInt', 'non-positive-int', 'intRange(max: 0)'),
3535
single('nonZeroInt', 'non-zero-int', 'union([negativeInt, positiveInt])'),

src/Type/IntRangeT.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
final readonly class IntRangeT implements Type
2020
{
2121
public function __construct(
22-
public int $min = PHP_INT_MIN,
23-
public int $max = PHP_INT_MAX,
22+
public ?int $min = null,
23+
public ?int $max = null,
2424
) {}
2525

2626
#[\Override]

src/Type/Visitor/Stringify.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,7 @@ public function intValueT(IntValueT $type): string
149149
#[\Override]
150150
public function intRangeT(IntRangeT $type): string
151151
{
152-
return \sprintf(
153-
'int<%s, %s>',
154-
$type->min === PHP_INT_MIN ? 'min' : $type->min,
155-
$type->max === PHP_INT_MAX ? 'max' : $type->max,
156-
);
152+
return \sprintf('int<%s, %s>', $type->min ?? 'min', $type->max ?? 'max');
157153
}
158154

159155
#[\Override]

src/Type/Visitor/WeakVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class WeakVisitor extends Fallback
1717
/**
1818
* @var \WeakReference<Visitor<TResult>>
1919
*/
20-
private \WeakReference $visitor;
20+
private readonly \WeakReference $visitor;
2121

2222
/**
2323
* @param Visitor<TResult> $visitor

src/Type/constructors.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function intT(int $value): IntValueT
4242
* @api
4343
* @return IntRangeT<int>
4444
*/
45-
function intRangeT(int $min = PHP_INT_MIN, int $max = PHP_INT_MAX): IntRangeT
45+
function intRangeT(?int $min = null, ?int $max = null): IntRangeT
4646
{
4747
return new IntRangeT($min, $max);
4848
}

0 commit comments

Comments
 (0)