diff --git a/src/Handler/UnionHandler.php b/src/Handler/UnionHandler.php index 4b2af5ada..16324d97f 100644 --- a/src/Handler/UnionHandler.php +++ b/src/Handler/UnionHandler.php @@ -14,7 +14,7 @@ final class UnionHandler implements SubscribingHandlerInterface { - static $aliases = ['boolean' => 'bool', 'integer' => 'int', 'double' => 'float']; + private static $aliases = ['boolean' => 'bool', 'integer' => 'int', 'double' => 'float']; /** * {@inheritdoc} @@ -51,10 +51,6 @@ public function serializeUnion( return $this->matchSimpleType($data, $type, $context); } - /** - * @param mixed $data - * @param array $type - */ public function deserializeUnion(DeserializationVisitorInterface $visitor, mixed $data, array $type, DeserializationContext $context) { if ($data instanceof \SimpleXMLElement) { @@ -69,8 +65,8 @@ private function matchSimpleType(mixed $data, array $type, Context $context) $dataType = $this->determineType($data, $type, $context->getFormat()); $alternativeName = null; - if (isset($aliases[$dataType])) { - $alternativeName = $aliases[$dataType]; + if (isset(static::$aliases[$dataType])) { + $alternativeName = static::$aliases[$dataType]; } foreach ($type['params'] as $possibleType) { @@ -103,13 +99,15 @@ private function reorderTypes(array $type): array return $type; } - private function determineType(mixed $data, array $type, string $format): string + private function determineType(mixed $data, array $type, string $format): string|null { foreach ($this->reorderTypes($type)['params'] as $possibleType) { if ($this->testPrimitive($data, $possibleType['name'], $format)) { return $possibleType['name']; } } + + return null; } private function testPrimitive(mixed $data, string $type, string $format): bool @@ -130,5 +128,7 @@ private function testPrimitive(mixed $data, string $type, string $format): bool case 'string': return (string) $data === (string) $data; } + + return false; } } diff --git a/tests/Metadata/Driver/UnionTypedPropertiesDriverTest.php b/tests/Metadata/Driver/UnionTypedPropertiesDriverTest.php index 8802ab9e0..138efc1b4 100644 --- a/tests/Metadata/Driver/UnionTypedPropertiesDriverTest.php +++ b/tests/Metadata/Driver/UnionTypedPropertiesDriverTest.php @@ -50,7 +50,7 @@ public function testInferUnionTypesShouldResultInManyTypes() ], ], ], - $m->propertyMetadata['data']->type + $m->propertyMetadata['data']->type, ); } diff --git a/tests/Serializer/BaseSerializationTestCase.php b/tests/Serializer/BaseSerializationTestCase.php index 52b04cd0d..7c089a498 100644 --- a/tests/Serializer/BaseSerializationTestCase.php +++ b/tests/Serializer/BaseSerializationTestCase.php @@ -1987,7 +1987,6 @@ public function testSerializingUnionDocBlockTypesProperties() $object = new UnionTypedDocBlockProperty(1.236); self::assertEquals(static::getContent('data_float'), $this->serialize($object)); - } public function testThrowingExceptionWhenDeserializingUnionDocBlockTypes()