Skip to content

Commit c31e050

Browse files
committed
Generated types
1 parent eabbcd8 commit c31e050

File tree

3 files changed

+82
-7
lines changed

3 files changed

+82
-7
lines changed

spec/ComplexType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ public function typeCode(): string
2828
$imports = implode(
2929
'',
3030
array_map(
31-
static fn (string $class): string => "\nuse {$class};",
31+
static fn(string $class): string => "\nuse {$class};",
3232
$this->imports,
33-
)
33+
),
3434
);
35-
$imports = $imports === '' ? '' : $imports."\n";
35+
$imports = $imports === '' ? '' : $imports . "\n";
3636
$templates = implode(
3737
'',
3838
array_map(

src/Alias/BoolType.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Typhoon\Type\Alias;
6+
7+
use Typhoon\Type\FalseType;
8+
use Typhoon\Type\TrueType;
9+
use Typhoon\Type\Type;
10+
use Typhoon\Type\TypeVisitor;
11+
use Typhoon\Type\UnionType;
12+
13+
/**
14+
* @internal
15+
* @psalm-internal Typhoon\Type
16+
* @implements Type<bool>
17+
*/
18+
enum BoolType implements Type
19+
{
20+
case Type;
21+
22+
public function accept(TypeVisitor $visitor): mixed
23+
{
24+
/** @var UnionType */
25+
static $type = new UnionType([
26+
FalseType::Type,
27+
TrueType::Type,
28+
]);
29+
30+
return $visitor->union($type);
31+
}
32+
}

src/types.php

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,61 @@
44

55
namespace Typhoon\Type;
66

7+
use Typhoon\Type\Alias\FloatMaxType;
8+
use Typhoon\Type\Alias\FloatMinType;
9+
use Typhoon\Type\Alias\IntMaxType;
10+
use Typhoon\Type\Alias\IntMinType;
11+
712
const neverT = NeverType::Type;
13+
814
const voidT = VoidType::Type;
15+
916
const nullT = NullType::Type;
17+
1018
const falseT = FalseType::Type;
19+
1120
const trueT = TrueType::Type;
21+
22+
const boolT = Alias\BoolType::Type;
23+
1224
const intT = Alias\IntType::Type;
13-
const intMinT = Alias\IntMinType::Type;
14-
const intMaxT = Alias\IntMaxType::Type;
25+
26+
const intMinT = IntMinType::Type;
27+
28+
const intMaxT = IntMaxType::Type;
29+
30+
/**
31+
* @api
32+
* @param Type<int> $min
33+
* @param Type<int> $max
34+
* @return Type<int>
35+
*/
36+
function intT(Type $min = IntMinType::Type, Type $max = IntMaxType::Type): Type
37+
{
38+
return new IntRangeType($min, $max);
39+
}
40+
1541
const floatT = Alias\FloatType::Type;
16-
const floatMinT = Alias\FloatMinType::Type;
17-
const floatMaxT = Alias\FloatMaxType::Type;
42+
43+
const floatMinT = FloatMinType::Type;
44+
45+
const floatMaxT = FloatMaxType::Type;
46+
47+
/**
48+
* @api
49+
* @param Type<float> $min
50+
* @param Type<float> $max
51+
* @return Type<float>
52+
*/
53+
function floatT(Type $min = FloatMinType::Type, Type $max = FloatMaxType::Type): Type
54+
{
55+
return new FloatRangeType($min, $max);
56+
}
57+
1858
const stringT = StringType::Type;
59+
1960
const resourceT = ResourceType::Type;
61+
2062
const arrayKeyT = Alias\ArrayKeyType::Type;
63+
2164
const mixedT = Alias\MixedType::Type;

0 commit comments

Comments
 (0)