Skip to content

Commit 0fb588c

Browse files
committed
feat: simplify checks
1 parent 68646e0 commit 0fb588c

File tree

2 files changed

+15
-27
lines changed

2 files changed

+15
-27
lines changed

src/DataConverter/DataConverter.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,14 @@ public function fromPayload(Payload $payload, $type)
5252
}
5353

5454
$type = Type::create($type);
55-
if (\in_array($type->getName(), [Type::TYPE_VOID, Type::TYPE_NULL, Type::TYPE_FALSE, Type::TYPE_TRUE], true)) {
56-
return match ($type->getName()) {
57-
Type::TYPE_VOID, Type::TYPE_NULL => null,
58-
Type::TYPE_TRUE => true,
59-
Type::TYPE_FALSE => false,
60-
};
61-
}
6255

63-
return $this->converters[$encoding]->fromPayload($payload, $type);
56+
return match ($type->getName()) {
57+
Type::TYPE_VOID,
58+
Type::TYPE_NULL => null,
59+
Type::TYPE_TRUE => true,
60+
Type::TYPE_FALSE => false,
61+
default => $this->converters[$encoding]->fromPayload($payload, $type),
62+
};
6463
}
6564

6665
/**

src/DataConverter/Type.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,14 @@ public static function fromReflectionType(\ReflectionType $type): self
7979
*/
8080
public static function create($type): Type
8181
{
82-
switch (true) {
83-
case $type instanceof ReturnType:
84-
return new self($type->name, $type->nullable);
85-
86-
case $type instanceof self:
87-
return $type;
88-
89-
case \is_string($type):
90-
return new self($type);
91-
92-
case $type instanceof \ReflectionClass:
93-
return self::fromReflectionClass($type);
94-
95-
case $type instanceof \ReflectionType:
96-
return self::fromReflectionType($type);
97-
98-
default:
99-
return new self();
100-
}
82+
return match (true) {
83+
$type instanceof ReturnType => new self($type->name, $type->nullable),
84+
$type instanceof self => $type,
85+
\is_string($type) => new self($type),
86+
$type instanceof \ReflectionClass => self::fromReflectionClass($type),
87+
$type instanceof \ReflectionType => self::fromReflectionType($type),
88+
default => new self(),
89+
};
10190
}
10291

10392
public function getName(): string

0 commit comments

Comments
 (0)