Skip to content

Commit fbdb806

Browse files
committed
fix: pass invalid deserialized data type using get_debug_type
1 parent 6fb58f9 commit fbdb806

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/InvalidDeserializedData.php

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

55
namespace Lendable\Json;
66

7-
class InvalidDeserializedData extends \RuntimeException implements Failure
7+
final class InvalidDeserializedData extends \RuntimeException implements Failure
88
{
99
public function __construct(string $unexpectedType)
1010
{

src/Serializer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
final readonly class Serializer
88
{
99
/**
10-
* @phpstan-param array<mixed> $data
10+
* @param array<mixed> $data
1111
*
1212
* @throws SerializationFailed
1313
*/
@@ -26,7 +26,7 @@ public function serialize(array $data): string
2626
* @throws DeserializationFailed
2727
* @throws InvalidDeserializedData
2828
*
29-
* @phpstan-return array<mixed>
29+
* @return array<mixed>
3030
*/
3131
public function deserialize(string $json): array
3232
{
@@ -37,7 +37,7 @@ public function deserialize(string $json): array
3737
}
3838

3939
if (!\is_array($data)) {
40-
throw new InvalidDeserializedData(\gettype($data));
40+
throw new InvalidDeserializedData(\get_debug_type($data));
4141
}
4242

4343
return $data;

tests/unit/SerializerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ public function it_throws_when_deserializing_if_the_result_is_not_an_array(strin
138138
*/
139139
public static function provideNonArrayRoots(): iterable
140140
{
141-
yield 'true' => ['true', 'boolean'];
142-
yield 'false' => ['false', 'boolean'];
143-
yield 'null' => ['null', 'NULL'];
144-
yield 'integer' => ['5', 'integer'];
145-
yield 'float' => ['1.5', 'double'];
141+
yield 'true' => ['true', 'bool'];
142+
yield 'false' => ['false', 'bool'];
143+
yield 'null' => ['null', 'null'];
144+
yield 'integer' => ['5', 'int'];
145+
yield 'float' => ['1.5', 'float'];
146146
yield 'string' => ['"foo"', 'string'];
147147
}
148148

0 commit comments

Comments
 (0)