Skip to content

Commit 29f6673

Browse files
committed
Fix linter issues
1 parent 9b30104 commit 29f6673

File tree

8 files changed

+26
-29
lines changed

8 files changed

+26
-29
lines changed

src/Platform/Platform.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ protected function formatCoercers(iterable $coercers): array
7979

8080
public function getTypeCoercers(): iterable
8181
{
82-
// TODO
83-
return $this->coercers;
82+
foreach ($this->coercers as $type => $coercer) {
83+
yield $coercer => [$type];
84+
}
8485
}
8586

8687
public function isFeatureSupported(GrammarFeature $feature): bool

src/Type/BackedEnumType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
/**
1111
* @template TEnum of \BackedEnum = \BackedEnum
12-
* @template-extends AsymmetricType<value-of<TEnum>, TEnum>
12+
* @template-extends AsymmetricType<int|string, TEnum>
1313
*/
1414
class BackedEnumType extends AsymmetricType
1515
{

src/Type/Builder/BackedEnumTypeBuilder.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
/**
1515
* @template TEnum of \BackedEnum = \BackedEnum
16-
* @template TResult of mixed = mixed
17-
* @template-extends Builder<NamedTypeNode, TypeInterface<TResult>>
16+
* @template-extends Builder<NamedTypeNode, TypeInterface<TEnum|int|string>>
1817
*/
1918
class BackedEnumTypeBuilder extends Builder
2019
{
@@ -32,7 +31,7 @@ public function isSupported(TypeStatement $stmt): bool
3231
}
3332

3433
/**
35-
* @param \ReflectionEnum<\BackedEnum> $reflection
34+
* @param \ReflectionEnum<TEnum> $reflection
3635
*
3736
* @return non-empty-string
3837
* @throws InternalTypeException
@@ -52,47 +51,44 @@ private function getBackedEnumType(\ReflectionEnum $reflection, NamedTypeNode $s
5251
return $type->getName();
5352
}
5453

55-
public function build(TypeStatement $stmt, BuildingContext $context): TypeInterface
54+
public function build(TypeStatement $stmt, BuildingContext $context): BackedEnumType
5655
{
5756
$this->expectNoShapeFields($stmt);
5857
$this->expectNoTemplateArguments($stmt);
5958

60-
$reflection = $this->createReflectionEnum($stmt);
59+
/** @var class-string<TEnum> $class */
60+
$class = $stmt->name->toString();
6161

62+
$reflection = $this->createReflectionEnum($class, $stmt);
6263
$definition = $this->getBackedEnumType($reflection, $stmt);
6364

6465
return new BackedEnumType(
65-
/** @phpstan-ignore-next-line : The stmt name contains class-string<TEnum> */
66-
class: $stmt->name->toString(),
66+
class: $class,
6767
/** @phpstan-ignore-next-line : The "getTypeByStatement" returns TypeInterface<value-of<TEnum>> */
6868
type: $context->getTypeByDefinition($definition),
6969
);
7070
}
7171

7272
/**
73-
* @return \ReflectionEnum<\BackedEnum>
73+
* @param class-string<TEnum> $class
74+
* @return \ReflectionEnum<TEnum>
7475
* @throws InternalTypeException
7576
*/
76-
protected function createReflectionEnum(NamedTypeNode $statement): \ReflectionEnum
77+
protected function createReflectionEnum(string $class, NamedTypeNode $stmt): \ReflectionEnum
7778
{
7879
try {
79-
/**
80-
* @var \ReflectionEnum<\BackedEnum> $reflection
81-
*
82-
* @phpstan-ignore-next-line
83-
*/
84-
$reflection = new \ReflectionEnum($statement->name->toString());
80+
$reflection = new \ReflectionEnum($class);
8581
} catch (\ReflectionException $e) {
8682
throw InternalTypeException::becauseInternalTypeErrorOccurs(
87-
type: $statement,
83+
type: $stmt,
8884
message: 'The "{{type}}" must be an existing enum',
8985
previous: $e,
9086
);
9187
}
9288

9389
if ($reflection->getCases() === []) {
9490
throw InternalTypeException::becauseInternalTypeErrorOccurs(
95-
type: $statement,
91+
type: $stmt,
9692
message: 'The "{{type}}" enum requires at least one case',
9793
);
9894
}

src/Type/Builder/ClassTypeBuilder.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515

1616
/**
1717
* @template TObject of object = object
18-
* @template TResult of object|array = object|array<array-key, mixed>
19-
* @template-extends Builder<NamedTypeNode, TypeInterface<TResult|TObject>>
18+
* @template-extends Builder<NamedTypeNode, TypeInterface<object|array<array-key, mixed>|TObject>>
2019
*/
2120
class ClassTypeBuilder extends Builder
2221
{
@@ -59,7 +58,7 @@ public function build(TypeStatement $stmt, BuildingContext $context): ClassType
5958
/** @var class-string<TObject> $class */
6059
$class = $stmt->name->toString();
6160

62-
/** @var ClassType<TObject, TResult> */
61+
/** @var ClassType<TObject> */
6362
return new ClassType(
6463
metadata: $this->meta->getClassMetadata(
6564
class: new \ReflectionClass($class),

src/Type/ClassType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212

1313
/**
1414
* @template TObject of object = object
15-
* @template TResult of object|array = object|array<array-key, mixed>
16-
* @template-extends AsymmetricType<TResult, TObject>
15+
* @template-extends AsymmetricType<object|array<array-key, mixed>, TObject>
1716
*/
1817
class ClassType extends AsymmetricType
1918
{

src/Type/ClassType/ClassToArrayType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
/**
1818
* @template TObject of object = object
19-
* @template-covariant TResult of object|array = object|array<array-key, mixed>
20-
* @template-implements TypeInterface<TResult>
19+
* @template-implements TypeInterface<object|array<array-key, mixed>>
2120
*/
2221
class ClassToArrayType implements TypeInterface
2322
{

src/Type/ObjectType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
use TypeLang\Mapper\Type\ObjectType\ObjectToArrayType;
99

1010
/**
11-
* @template TResult of object|array = object|array<array-key, mixed>
12-
* @template-extends AsymmetricType<TResult, object>
11+
* @template-extends AsymmetricType<object|array<array-key, mixed>, object>
1312
*/
1413
final class ObjectType extends AsymmetricType
1514
{

src/Type/UnitEnumType/UnitEnumFromStringType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ private function getEnumCases(string $enum): array
4242
$result = [];
4343

4444
foreach ($enum::cases() as $case) {
45+
if ($case->name === '') {
46+
continue;
47+
}
48+
4549
$result[] = $case->name;
4650
}
4751

0 commit comments

Comments
 (0)