Skip to content

Commit 3a4f4a8

Browse files
committed
test: static type errors
1 parent fdd0857 commit 3a4f4a8

File tree

4 files changed

+24
-60
lines changed

4 files changed

+24
-60
lines changed

phpstan-baseline.neon

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,2 @@
11
parameters:
2-
ignoreErrors:
3-
-
4-
message: "#^Method WayOfDev\\\\Serializer\\\\Normalizers\\\\RamseyUuidNormalizer\\:\\:normalize\\(\\) return type has no value type specified in iterable type array\\.$#"
5-
count: 1
6-
path: src/Normalizers/RamseyUuidNormalizer.php
7-
8-
-
9-
message: "#^Method WayOfDev\\\\Serializer\\\\Normalizers\\\\RamseyUuidNormalizer\\:\\:normalize\\(\\) return type with generic class ArrayObject does not specify its types\\: TKey, TValue$#"
10-
count: 1
11-
path: src/Normalizers/RamseyUuidNormalizer.php
12-
13-
-
14-
message: "#^Parameter \\#1 \\$object \\(Ramsey\\\\Uuid\\\\UuidInterface\\) of method WayOfDev\\\\Serializer\\\\Normalizers\\\\RamseyUuidNormalizer\\:\\:normalize\\(\\) should be contravariant with parameter \\$object \\(mixed\\) of method Symfony\\\\Component\\\\Serializer\\\\Normalizer\\\\NormalizerInterface\\:\\:normalize\\(\\)$#"
15-
count: 1
16-
path: src/Normalizers/RamseyUuidNormalizer.php
2+
ignoreErrors: []

psalm-baseline.xml

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="5.24.0@462c80e31c34e58cc4f750c656be3927e80e550e">
2+
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
33
<file src="src/Bridge/Laravel/Http/ResponseFactory.php">
44
<PossiblyUnusedMethod>
55
<code><![CDATA[empty]]></code>
@@ -15,20 +15,17 @@
1515
'metadataLoader' => $config->get('serializer.metadataLoader'),
1616
]]]></code>
1717
</MixedArgumentTypeCoercion>
18-
<MixedInferredReturnType>
19-
<code><![CDATA[EncoderRegistrationStrategy]]></code>
20-
<code><![CDATA[NormalizerRegistrationStrategy]]></code>
21-
</MixedInferredReturnType>
22-
<MixedReturnStatement>
23-
<code><![CDATA[$app->make($strategyFQCN)]]></code>
24-
<code><![CDATA[$app->make($strategyFQCN, [
25-
'loader' => $loader,
26-
'debugMode' => $config->debug(),
27-
])]]></code>
28-
</MixedReturnStatement>
2918
<PossiblyUnusedMethod>
3019
<code><![CDATA[boot]]></code>
3120
</PossiblyUnusedMethod>
21+
<UnnecessaryVarAnnotation>
22+
<code><![CDATA[EncoderRegistrationStrategy]]></code>
23+
<code><![CDATA[EncoderRegistryInterface]]></code>
24+
<code><![CDATA[LoaderInterface]]></code>
25+
<code><![CDATA[NormalizerRegistrationStrategy]]></code>
26+
<code><![CDATA[NormalizerRegistryInterface]]></code>
27+
<code><![CDATA[Repository]]></code>
28+
</UnnecessaryVarAnnotation>
3229
</file>
3330
<file src="src/DefaultNormalizerRegistrationStrategy.php">
3431
<PossiblyUnusedMethod>
@@ -65,17 +62,6 @@
6562
</PossiblyUnusedMethod>
6663
</file>
6764
<file src="tests/src/Functional/Bridge/Laravel/Providers/SerializerServiceProviderTest.php">
68-
<MixedArgument>
69-
<code><![CDATA[$encoders]]></code>
70-
</MixedArgument>
71-
<MixedAssignment>
72-
<code><![CDATA[$encodersRegistry]]></code>
73-
<code><![CDATA[$normalizersRegistry]]></code>
74-
</MixedAssignment>
75-
<MixedMethodCall>
76-
<code><![CDATA[all]]></code>
77-
<code><![CDATA[all]]></code>
78-
</MixedMethodCall>
7965
<PossiblyUnusedMethod>
8066
<code><![CDATA[it_registers_config]]></code>
8167
<code><![CDATA[it_registers_encoders_registry]]></code>
@@ -95,10 +81,6 @@
9581
</PossiblyUnusedMethod>
9682
</file>
9783
<file src="tests/src/Functional/EncoderRegistryTest.php">
98-
<MixedArgument>
99-
<code><![CDATA[$this->app?->make(EncoderRegistrationStrategy::class)]]></code>
100-
<code><![CDATA[$this->app?->make(EncoderRegistrationStrategy::class)]]></code>
101-
</MixedArgument>
10284
<PossiblyNullArgument>
10385
<code><![CDATA[$this->app?->make(EncoderRegistrationStrategy::class)]]></code>
10486
<code><![CDATA[$this->app?->make(EncoderRegistrationStrategy::class)]]></code>
@@ -128,11 +110,6 @@
128110
</PossiblyUnusedMethod>
129111
</file>
130112
<file src="tests/src/Functional/NormalizerRegistryTest.php">
131-
<MixedArgument>
132-
<code><![CDATA[app(NormalizerRegistrationStrategy::class)]]></code>
133-
<code><![CDATA[app(NormalizerRegistrationStrategy::class)]]></code>
134-
<code><![CDATA[app(NormalizerRegistrationStrategy::class)]]></code>
135-
</MixedArgument>
136113
<PossiblyUnusedMethod>
137114
<code><![CDATA[construct_with_default_normalizers]]></code>
138115
<code><![CDATA[it_gets_all_registered_normalizers]]></code>
@@ -141,13 +118,6 @@
141118
</PossiblyUnusedMethod>
142119
</file>
143120
<file src="tests/src/Functional/Normalizers/RamseyUuidNormalizerTest.php">
144-
<ImplicitToStringCast>
145-
<code><![CDATA[$manager->serialize($payload, $format)]]></code>
146-
</ImplicitToStringCast>
147-
<PossiblyNullReference>
148-
<code><![CDATA[deserialize]]></code>
149-
<code><![CDATA[serialize]]></code>
150-
</PossiblyNullReference>
151121
<PossiblyUnusedMethod>
152122
<code><![CDATA[it_deserializes_using_serialize_manager]]></code>
153123
<code><![CDATA[it_serializes_using_serializer_manager]]></code>

src/Normalizers/RamseyUuidNormalizer.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use ArrayObject;
88
use InvalidArgumentException;
9+
use Override;
910
use Ramsey\Uuid\Uuid;
1011
use Ramsey\Uuid\UuidInterface;
1112
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
@@ -19,14 +20,17 @@
1920
final class RamseyUuidNormalizer implements NormalizerInterface, DenormalizerInterface
2021
{
2122
/**
22-
* @param UuidInterface $object
23+
* @param mixed $data
2324
* @param array<array-key, mixed> $context
24-
*
25-
* @psalm-suppress MoreSpecificImplementedParamType
2625
*/
27-
public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|ArrayObject|null
26+
#[Override]
27+
public function normalize(mixed $data, ?string $format = null, array $context = []): string
2828
{
29-
return $object->toString();
29+
if (!$data instanceof UuidInterface) {
30+
throw new NotNormalizableValueException('Expected UuidInterface instance');
31+
}
32+
33+
return $data->toString();
3034
}
3135

3236
/**

tests/src/Functional/Normalizers/RamseyUuidNormalizerTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ public static function serializeDataProvider(): Traversable
4949
public function it_serializes_using_serializer_manager(string $expected, mixed $payload, string $format): void
5050
{
5151
$manager = $this->app?->get(SerializerManager::class);
52+
self::assertNotNull($manager, 'SerializerManager should not be null');
5253

53-
self::assertSame($expected, preg_replace('/\s+/', '', $manager->serialize($payload, $format)));
54+
$serialized = $manager->serialize($payload, $format);
55+
self::assertIsString($serialized);
56+
self::assertSame($expected, preg_replace('/\s+/', '', $serialized));
5457
}
5558

5659
/**
@@ -61,6 +64,7 @@ public function it_serializes_using_serializer_manager(string $expected, mixed $
6164
public function it_deserializes_using_serialize_manager(): void
6265
{
6366
$manager = $this->app?->get(SerializerManager::class);
67+
self::assertNotNull($manager, 'SerializerManager should not be null');
6468

6569
$result = $manager->deserialize(
6670
'{"uuid":"1d96a152-9838-43a0-a189-159befc9e38f","name":"some"}',

0 commit comments

Comments
 (0)