Skip to content

Commit a89f73f

Browse files
committed
Sync with template
1 parent d7b307b commit a89f73f

File tree

8 files changed

+25
-13
lines changed

8 files changed

+25
-13
lines changed

generator/TypeSpec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ public function nativeType(): string
109109
}
110110

111111
return ($nullable ? '?' : '') . match ($container) {
112+
'numeric-string', 'non-empty-string', 'class-string' => 'string',
113+
'list', 'non-empty-list' => 'array',
112114
'Variance' => Variance::class,
113115
'Type' => Type::class,
114-
'list', 'non-empty-list' => 'array',
115-
'non-empty-string', 'class-string' => 'string',
116116
default => $container,
117117
};
118118
}

generator/types.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
type('null', 'null'),
1414
type('false', 'false'),
1515
type('true', 'true'),
16-
type('intRange', 'int')->prop('min', '?int')->prop('max', '?int'),
16+
type('intRange', 'int')->prop('min', '?numeric-string')->prop('max', '?numeric-string'),
1717
type('floatRange', 'float')->prop('min', '?float')->prop('max', '?float'),
1818
type('stringValue', 'string')->prop('value', 'string'),
1919
type('string', 'string'),

src/Alias/NegativeIntT.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ enum NegativeIntT implements Type
2020
public function accept(TypeVisitor $visitor): mixed
2121
{
2222
/** @var IntRangeT */
23-
static $type = new IntRangeT(null, -1);
23+
static $type = new IntRangeT(null, '-1');
2424

2525
return $visitor->intRange($type);
2626
}

src/Alias/NonNegativeIntT.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ enum NonNegativeIntT implements Type
2020
public function accept(TypeVisitor $visitor): mixed
2121
{
2222
/** @var IntRangeT */
23-
static $type = new IntRangeT(0, null);
23+
static $type = new IntRangeT('0', null);
2424

2525
return $visitor->intRange($type);
2626
}

src/Alias/NonPositiveIntT.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ enum NonPositiveIntT implements Type
2020
public function accept(TypeVisitor $visitor): mixed
2121
{
2222
/** @var IntRangeT */
23-
static $type = new IntRangeT(null, 0);
23+
static $type = new IntRangeT(null, '0');
2424

2525
return $visitor->intRange($type);
2626
}

src/Alias/PositiveIntT.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ enum PositiveIntT implements Type
2020
public function accept(TypeVisitor $visitor): mixed
2121
{
2222
/** @var IntRangeT */
23-
static $type = new IntRangeT(1, null);
23+
static $type = new IntRangeT('1', null);
2424

2525
return $visitor->intRange($type);
2626
}

src/IntRangeT.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@
1212
*/
1313
final class IntRangeT implements Type
1414
{
15-
public readonly ?int $min;
15+
/** @var ?numeric-string */
16+
public readonly ?string $min;
1617

17-
public readonly ?int $max;
18+
/** @var ?numeric-string */
19+
public readonly ?string $max;
1820

1921
/**
2022
* @internal
2123
* @psalm-internal Typhoon\Type
24+
* @param ?numeric-string $min
25+
* @param ?numeric-string $max
2226
*/
23-
public function __construct(?int $min, ?int $max)
27+
public function __construct(?string $min, ?string $max)
2428
{
2529
$this->min = $min;
2630
$this->max = $max;

src/types.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,28 @@
3434

3535
/**
3636
* @api
37+
* @param int|numeric-string $value
3738
* @return Type<int>
3839
*/
39-
function intT(int $value): Type
40+
function intT(int|string $value): Type
4041
{
42+
$value = (string) $value;
43+
4144
return new IntRangeT($value, $value);
4245
}
4346

4447
/**
4548
* @api
49+
* @param null|int|numeric-string $min
50+
* @param null|int|numeric-string $max
4651
* @return Type<int>
4752
*/
48-
function intRangeT(?int $min = null, ?int $max = null): Type
53+
function intRangeT(null|int|string $min = null, null|int|string $max = null): Type
4954
{
50-
return new IntRangeT($min, $max);
55+
return new IntRangeT(
56+
$min === null ? null : (string) $min,
57+
$max === null ? null : (string) $max,
58+
);
5159
}
5260

5361
const negativeIntT = NegativeIntT::T;

0 commit comments

Comments
 (0)