Skip to content

Commit fad176f

Browse files
committed
Revert "Add AtomicType interface"
This reverts commit 2178887. Revert "Add TermType and NormType" This reverts commit 68eeea6.
1 parent cd00835 commit fad176f

16 files changed

Lines changed: 47 additions & 113 deletions

generator/Generator.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Nette\PhpGenerator\PhpNamespace;
1313
use Nette\PhpGenerator\PsrPrinter;
1414
use Symfony\Component\Finder\Finder;
15-
use Typhoon\Type\Internal\TermType;
1615
use Typhoon\Type\Type;
1716
use Typhoon\Type\TypeVisitor;
1817

@@ -49,9 +48,9 @@ private static function generateTypes(): void
4948
{
5049
foreach (self::types() as $type) {
5150
if ($type->properties === []) {
52-
self::writeClass(self::generateEnumType($type));
51+
self::writeClass(self::generateAtomicType($type));
5352
} else {
54-
self::writeClass(self::generateClassType($type));
53+
self::writeClass(self::generateComplexType($type));
5554
}
5655
}
5756
}
@@ -100,11 +99,11 @@ private static function generateDefaultVisitor(): void
10099
self::writeClass($visitor, 'Visitor');
101100
}
102101

103-
private static function generateEnumType(TypeSpec $type): EnumType
102+
private static function generateAtomicType(TypeSpec $type): EnumType
104103
{
105104
$enum = (new EnumType($type->shortClassName()))
106-
->setComment(self::GENERATED_NOTICE . "\n@api\n@implements {$type->shortInterfaceName()}<{$type->type}>")
107-
->addImplement($type->interface);
105+
->setComment(self::GENERATED_NOTICE . "\n@api\n@implements Type<{$type->type}>")
106+
->addImplement(Type::class);
108107
$enum->addCase('T');
109108
$enum->addMethod('accept')
110109
->setReturnType('mixed')
@@ -114,11 +113,11 @@ private static function generateEnumType(TypeSpec $type): EnumType
114113
return $enum;
115114
}
116115

117-
private static function generateClassType(TypeSpec $type): ClassType
116+
private static function generateComplexType(TypeSpec $typeSpec): ClassType
118117
{
119118
$typeComment = self::GENERATED_NOTICE . "\n@api";
120119

121-
foreach ($type->templates as $templateSpec) {
120+
foreach ($typeSpec->templates as $templateSpec) {
122121
$typeComment .= \sprintf(
123122
"\n@template %s%s%s",
124123
$templateSpec->name,
@@ -127,18 +126,18 @@ private static function generateClassType(TypeSpec $type): ClassType
127126
);
128127
}
129128

130-
$typeComment .= "\n@implements {$type->shortInterfaceName()}<{$type->type}>";
129+
$typeComment .= "\n@implements Type<{$typeSpec->type}>";
131130

132-
$class = (new ClassType($type->shortClassName()))
131+
$class = (new ClassType($typeSpec->shortClassName()))
133132
->setFinal()
134133
->setComment($typeComment)
135-
->addImplement($type->interface);
134+
->addImplement(Type::class);
136135

137136
$constructorComment = "@internal\n@psalm-internal Typhoon\\Type";
138137
$constructorParams = [];
139138
$constructorBody = '';
140139

141-
foreach ($type->properties as $propertySpec) {
140+
foreach ($typeSpec->properties as $propertySpec) {
142141
$nativeType = $propertySpec->nativeType();
143142
$class->addProperty($propertySpec->name)
144143
->setReadOnly()
@@ -158,7 +157,7 @@ private static function generateClassType(TypeSpec $type): ClassType
158157
$class
159158
->addMethod('accept')
160159
->setReturnType('mixed')
161-
->addBody(\sprintf('return $visitor->%s($this);', $type->name))
160+
->addBody(\sprintf('return $visitor->%s($this);', $typeSpec->name))
162161
->addParameter('visitor')->setType(TypeVisitor::class);
163162

164163
return $class;
@@ -186,7 +185,6 @@ private static function writeClass(ClassType|InterfaceType|EnumType $class, ?str
186185
$namespace = $file->addNamespace(new PhpNamespace(self::NAMESPACE . ($namespace === null ? '' : '\\' . $namespace)));
187186
$namespace->add($class);
188187
$namespace->addUse(Type::class);
189-
$namespace->addUse(TermType::class);
190188

191189
file_put_contents($fileName, (new PsrPrinter())->printFile($file));
192190
}

generator/TypeSpec.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ final class TypeSpec
1212
/**
1313
* @param non-empty-string $name
1414
* @param non-empty-string $type
15-
* @param class-string<Type> $interface
1615
* @param list<TemplateSpec> $templates
1716
* @param list<PropertySpec> $properties
1817
*/
1918
public function __construct(
2019
public readonly string $name,
2120
public readonly string $type,
22-
public readonly string $interface,
2321
public readonly array $templates = [],
2422
public readonly array $properties = [],
2523
) {}
@@ -40,13 +38,6 @@ public function className(): string
4038
return 'Typhoon\Type\\' . $this->shortClassName();
4139
}
4240

43-
public function shortInterfaceName(): string
44-
{
45-
$interfaceParts = explode('\\', $this->interface);
46-
47-
return end($interfaceParts);
48-
}
49-
5041
/**
5142
* @param non-empty-string $name
5243
* @param ?non-empty-string $of
@@ -57,7 +48,6 @@ public function tpl(string $name, ?string $of = null, ?string $default = null):
5748
return new self(
5849
name: $this->name,
5950
type: $this->type,
60-
interface: $this->interface,
6151
templates: [
6252
...$this->templates,
6353
new TemplateSpec($name, $of, $default),
@@ -75,7 +65,6 @@ public function prop(string $name, string $type): self
7565
return new self(
7666
name: $this->name,
7767
type: $this->type,
78-
interface: $this->interface,
7968
templates: $this->templates,
8069
properties: [
8170
...$this->properties,
@@ -132,9 +121,8 @@ public function nativeType(): string
132121
/**
133122
* @param non-empty-string $name
134123
* @param non-empty-string $type
135-
* @param class-string<Type> $interface
136124
*/
137-
function type(string $name, string $type, string $interface = Type::class): TypeSpec
125+
function type(string $name, string $type): TypeSpec
138126
{
139-
return new TypeSpec($name, $type, $interface);
127+
return new TypeSpec($name, $type);
140128
}

generator/types.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,23 @@
44

55
namespace Typhoon\TypeGenerator;
66

7-
use Typhoon\Type\Internal\TermType;
8-
97
require_once __DIR__ . '/TypeSpec.php';
108

119
return [
1210
// trivial
13-
type('never', 'never', TermType::class),
14-
type('void', 'void', TermType::class),
15-
type('null', 'null', TermType::class),
16-
type('false', 'false', TermType::class),
17-
type('true', 'true', TermType::class),
11+
type('never', 'never'),
12+
type('void', 'void'),
13+
type('null', 'null'),
14+
type('false', 'false'),
15+
type('true', 'true'),
1816
type('intRange', 'int')->prop('min', '?numeric-string')->prop('max', '?numeric-string'),
1917
type('floatRange', 'float')->prop('min', '?numeric-string')->prop('max', '?numeric-string'),
20-
type('stringValue', 'string', TermType::class)->prop('value', 'string'),
21-
type('numericString', 'numeric-string', TermType::class),
22-
type('lowercaseString', 'lowercase-string', TermType::class),
23-
type('nonEmptyString', 'non-empty-string', TermType::class),
24-
type('string', 'string', TermType::class),
25-
type('resource', 'resource', TermType::class),
18+
type('stringValue', 'string')->prop('value', 'string'),
19+
type('numericString', 'numeric-string'),
20+
type('lowercaseString', 'lowercase-string'),
21+
type('nonEmptyString', 'non-empty-string'),
22+
type('string', 'string'),
23+
type('resource', 'resource'),
2624
// compound
2725
type('list', 'list<mixed>')->prop('valueType', 'Type')->prop('elements', 'array<non-negative-int, ArrayElement>'),
2826
type('array', 'array<mixed>')->prop('keyType', 'Type')->prop('valueType', 'Type')->prop('elements', 'array<ArrayElement>'),

src/FalseT.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44

55
namespace Typhoon\Type;
66

7-
use Typhoon\Type\Internal\TermType;
8-
97
/**
108
* This code is generated, do not edit it.
119
*
1210
* @api
13-
* @implements TermType<false>
11+
* @implements Type<false>
1412
*/
15-
enum FalseT implements TermType
13+
enum FalseT implements Type
1614
{
1715
case T;
1816

src/Internal/NormType.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/Internal/TermType.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/LowercaseStringT.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44

55
namespace Typhoon\Type;
66

7-
use Typhoon\Type\Internal\TermType;
8-
97
/**
108
* This code is generated, do not edit it.
119
*
1210
* @api
13-
* @implements TermType<lowercase-string>
11+
* @implements Type<lowercase-string>
1412
*/
15-
enum LowercaseStringT implements TermType
13+
enum LowercaseStringT implements Type
1614
{
1715
case T;
1816

src/NeverT.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44

55
namespace Typhoon\Type;
66

7-
use Typhoon\Type\Internal\TermType;
8-
97
/**
108
* This code is generated, do not edit it.
119
*
1210
* @api
13-
* @implements TermType<never>
11+
* @implements Type<never>
1412
*/
15-
enum NeverT implements TermType
13+
enum NeverT implements Type
1614
{
1715
case T;
1816

src/NonEmptyStringT.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44

55
namespace Typhoon\Type;
66

7-
use Typhoon\Type\Internal\TermType;
8-
97
/**
108
* This code is generated, do not edit it.
119
*
1210
* @api
13-
* @implements TermType<non-empty-string>
11+
* @implements Type<non-empty-string>
1412
*/
15-
enum NonEmptyStringT implements TermType
13+
enum NonEmptyStringT implements Type
1614
{
1715
case T;
1816

src/NullT.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44

55
namespace Typhoon\Type;
66

7-
use Typhoon\Type\Internal\TermType;
8-
97
/**
108
* This code is generated, do not edit it.
119
*
1210
* @api
13-
* @implements TermType<null>
11+
* @implements Type<null>
1412
*/
15-
enum NullT implements TermType
13+
enum NullT implements Type
1614
{
1715
case T;
1816

0 commit comments

Comments
 (0)