Skip to content

Commit 6c21785

Browse files
committed
Simplify Type internal codebase
1 parent cb073b6 commit 6c21785

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

src/Serializer/Type.php

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace League\Csv\Serializer;
1313

1414
use DateTimeInterface;
15-
1615
use ReflectionClass;
1716
use ReflectionNamedType;
1817
use ReflectionParameter;
@@ -43,7 +42,7 @@ enum Type: string
4342
case Array = 'array';
4443
case Iterable = 'iterable';
4544
case Enum = 'enum';
46-
case Date = 'date';
45+
case Date = DateTimeInterface::class;
4746

4847
public function equals(mixed $value): bool
4948
{
@@ -99,14 +98,6 @@ public static function list(ReflectionParameter|ReflectionProperty $reflectionPr
9998
$reflectionProperty instanceof ReflectionProperty => 'The property `'.$reflectionProperty->getName().'` must be typed.',
10099
});
101100

102-
return self::typeList($reflectionType);
103-
}
104-
105-
/**
106-
* @return list<array{0:Type, 1: ReflectionNamedType}>
107-
*/
108-
private static function typeList(ReflectionType $reflectionType): array
109-
{
110101
$foundTypes = static function (array $res, ReflectionType $reflectionType) {
111102
if (!$reflectionType instanceof ReflectionNamedType) {
112103
return $res;
@@ -120,20 +111,11 @@ private static function typeList(ReflectionType $reflectionType): array
120111
return $res;
121112
};
122113

123-
if ($reflectionType instanceof ReflectionNamedType) {
124-
$type = self::tryFromName($reflectionType->getName());
125-
if (null !== $type) {
126-
return [[$type, $reflectionType]];
127-
}
128-
129-
return [];
130-
}
131-
132-
if ($reflectionType instanceof ReflectionUnionType) {
133-
return array_reduce($reflectionType->getTypes(), $foundTypes, []);
134-
}
135-
136-
return [];
114+
return match (true) {
115+
$reflectionType instanceof ReflectionNamedType => $foundTypes([], $reflectionType),
116+
$reflectionType instanceof ReflectionUnionType => array_reduce($reflectionType->getTypes(), $foundTypes, []),
117+
default => [],
118+
};
137119
}
138120

139121
public static function tryFromReflectionType(ReflectionType $type): ?self

0 commit comments

Comments
 (0)