From 4db6d56c91c1657cd77c562ef19f940f139dd60f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 1 Jul 2021 11:27:18 +0200 Subject: [PATCH] [Serializer] add union types --- .../Serializer/Annotation/Context.php | 5 +- .../Annotation/DiscriminatorMap.php | 23 +------ .../Serializer/Annotation/Groups.php | 19 ++---- .../Serializer/Annotation/MaxDepth.php | 19 +----- .../Serializer/Annotation/SerializedName.php | 19 +----- .../CompiledClassMetadataCacheWarmer.php | 2 +- .../Serializer/Encoder/ChainEncoder.php | 2 +- .../Serializer/Encoder/CsvEncoder.php | 2 +- .../Serializer/Encoder/EncoderInterface.php | 2 +- .../Serializer/Encoder/JsonEncode.php | 4 +- .../Serializer/Encoder/JsonEncoder.php | 2 +- .../Serializer/Encoder/XmlEncoder.php | 17 ++--- .../Serializer/Encoder/YamlEncoder.php | 2 +- .../ClassDiscriminatorFromClassMetadata.php | 6 +- .../Mapping/ClassDiscriminatorMapping.php | 5 +- .../ClassDiscriminatorResolverInterface.php | 10 +-- .../Factory/CacheClassMetadataFactory.php | 4 +- .../Mapping/Factory/ClassMetadataFactory.php | 4 +- .../Factory/ClassMetadataFactoryInterface.php | 8 +-- .../Mapping/Factory/ClassResolverTrait.php | 8 +-- .../Factory/CompiledClassMetadataFactory.php | 4 +- .../Normalizer/AbstractNormalizer.php | 27 +++----- .../Normalizer/AbstractObjectNormalizer.php | 32 ++++------ .../Normalizer/ArrayDenormalizer.php | 4 +- .../ConstraintViolationListNormalizer.php | 6 +- .../ContextAwareDenormalizerInterface.php | 2 +- .../ContextAwareNormalizerInterface.php | 2 +- .../Normalizer/CustomNormalizer.php | 8 +-- .../Normalizer/DataUriNormalizer.php | 8 +-- .../Normalizer/DateIntervalNormalizer.php | 8 +-- .../Normalizer/DateTimeNormalizer.php | 8 +-- .../Normalizer/DateTimeZoneNormalizer.php | 8 +-- .../Normalizer/DenormalizableInterface.php | 2 +- .../Normalizer/DenormalizerInterface.php | 4 +- .../Normalizer/FormErrorNormalizer.php | 4 +- .../Normalizer/GetSetMethodNormalizer.php | 6 +- .../Normalizer/JsonSerializableNormalizer.php | 8 +-- .../Normalizer/MimeMessageNormalizer.php | 8 +-- .../Normalizer/NormalizerInterface.php | 4 +- .../Normalizer/ObjectNormalizer.php | 4 +- .../Normalizer/ProblemNormalizer.php | 4 +- .../Normalizer/PropertyNormalizer.php | 12 ++-- .../Serializer/Normalizer/UidNormalizer.php | 8 +-- .../Normalizer/UnwrappingDenormalizer.php | 4 +- .../Component/Serializer/Serializer.php | 18 +++--- .../Serializer/SerializerInterface.php | 4 +- .../Tests/Annotation/DiscriminatorMapTest.php | 63 ------------------- .../Tests/Annotation/GroupsTest.php | 32 ---------- .../Tests/Annotation/MaxDepthTest.php | 41 +----------- .../Tests/Annotation/SerializedNameTest.php | 21 ------- .../Fixtures/AbstractNormalizerDummy.php | 10 +-- .../Tests/Fixtures/DenormalizableDummy.php | 2 +- .../Serializer/Tests/Fixtures/Dummy.php | 2 +- .../Fixtures/NormalizableTraversableDummy.php | 2 +- .../Serializer/Tests/Fixtures/ScalarDummy.php | 2 +- .../Fixtures/StaticConstructorNormalizer.php | 2 +- .../Normalizer/UnwrappinDenormalizerTest.php | 6 +- 57 files changed, 143 insertions(+), 410 deletions(-) diff --git a/src/Symfony/Component/Serializer/Annotation/Context.php b/src/Symfony/Component/Serializer/Annotation/Context.php index 3d6464790c72e..d4b2ffcacf964 100644 --- a/src/Symfony/Component/Serializer/Annotation/Context.php +++ b/src/Symfony/Component/Serializer/Annotation/Context.php @@ -35,7 +35,7 @@ final class Context * * @throws InvalidArgumentException */ - public function __construct(array $options = [], array $context = [], array $normalizationContext = [], array $denormalizationContext = [], $groups = []) + public function __construct(array $options = [], array $context = [], array $normalizationContext = [], array $denormalizationContext = [], string|array $groups = []) { if (!$context) { if (!array_intersect((array_keys($options)), ['normalizationContext', 'groups', 'context', 'value', 'denormalizationContext'])) { @@ -48,9 +48,6 @@ public function __construct(array $options = [], array $context = [], array $nor $context = $options['value'] ?? $options['context'] ?? []; } } - if (!\is_string($groups) && !\is_array($groups)) { - throw new \TypeError(sprintf('"%s": Expected parameter $groups to be a string or an array of strings, got "%s".', __METHOD__, get_debug_type($groups))); - } $normalizationContext = $options['normalizationContext'] ?? $normalizationContext; $denormalizationContext = $options['denormalizationContext'] ?? $denormalizationContext; diff --git a/src/Symfony/Component/Serializer/Annotation/DiscriminatorMap.php b/src/Symfony/Component/Serializer/Annotation/DiscriminatorMap.php index d01287bfd398a..79c27c7bc79f4 100644 --- a/src/Symfony/Component/Serializer/Annotation/DiscriminatorMap.php +++ b/src/Symfony/Component/Serializer/Annotation/DiscriminatorMap.php @@ -25,32 +25,11 @@ #[\Attribute(\Attribute::TARGET_CLASS)] class DiscriminatorMap { - /** - * @var string - */ private $typeProperty; - - /** - * @var array - */ private $mapping; - /** - * @param string $typeProperty - * - * @throws InvalidArgumentException - */ - public function __construct($typeProperty, array $mapping = null) + public function __construct(string $typeProperty, array $mapping) { - if (\is_array($typeProperty)) { - trigger_deprecation('symfony/serializer', '5.3', 'Passing an array as first argument to "%s" is deprecated. Use named arguments instead.', __METHOD__); - - $mapping = $typeProperty['mapping'] ?? null; - $typeProperty = $typeProperty['typeProperty'] ?? null; - } elseif (!\is_string($typeProperty)) { - throw new \TypeError(sprintf('"%s": Argument $typeProperty was expected to be a string or array, got "%s".', __METHOD__, get_debug_type($typeProperty))); - } - if (empty($typeProperty)) { throw new InvalidArgumentException(sprintf('Parameter "typeProperty" of annotation "%s" cannot be empty.', static::class)); } diff --git a/src/Symfony/Component/Serializer/Annotation/Groups.php b/src/Symfony/Component/Serializer/Annotation/Groups.php index 0a251f786cc8c..198a79eb39ebf 100644 --- a/src/Symfony/Component/Serializer/Annotation/Groups.php +++ b/src/Symfony/Component/Serializer/Annotation/Groups.php @@ -32,27 +32,18 @@ class Groups /** * @param string|string[] $groups - * - * @throws InvalidArgumentException */ - public function __construct($groups) + public function __construct(string|array $groups) { - if (\is_string($groups)) { - $groups = (array) $groups; - } elseif (!\is_array($groups)) { - throw new \TypeError(sprintf('"%s": Parameter $groups is expected to be a string or an array of strings, got "%s".', __METHOD__, get_debug_type($groups))); - } elseif (isset($groups['value'])) { - trigger_deprecation('symfony/serializer', '5.3', 'Passing an array of properties as first argument to "%s" is deprecated. Use named arguments instead.', __METHOD__); + $groups = (array) $groups; - $groups = (array) $groups['value']; - } if (empty($groups)) { throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" cannot be empty.', static::class)); } foreach ($groups as $group) { - if (!\is_string($group)) { - throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a string or an array of strings.', static::class)); + if (!\is_string($group) || '' === $group) { + throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a string or an array of non-empty strings.', static::class)); } } @@ -60,8 +51,6 @@ public function __construct($groups) } /** - * Gets groups. - * * @return string[] */ public function getGroups() diff --git a/src/Symfony/Component/Serializer/Annotation/MaxDepth.php b/src/Symfony/Component/Serializer/Annotation/MaxDepth.php index e0cc41ebd119e..73c8a9e172a8c 100644 --- a/src/Symfony/Component/Serializer/Annotation/MaxDepth.php +++ b/src/Symfony/Component/Serializer/Annotation/MaxDepth.php @@ -25,26 +25,11 @@ #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)] class MaxDepth { - /** - * @var int - */ private $maxDepth; - /** - * @param int $maxDepth - */ - public function __construct($maxDepth) + public function __construct(int $maxDepth) { - if (\is_array($maxDepth)) { - trigger_deprecation('symfony/serializer', '5.3', 'Passing an array as first argument to "%s" is deprecated. Use named arguments instead.', __METHOD__); - - if (!isset($maxDepth['value'])) { - throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" should be set.', static::class)); - } - $maxDepth = $maxDepth['value']; - } - - if (!\is_int($maxDepth) || $maxDepth <= 0) { + if ($maxDepth <= 0) { throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a positive integer.', static::class)); } diff --git a/src/Symfony/Component/Serializer/Annotation/SerializedName.php b/src/Symfony/Component/Serializer/Annotation/SerializedName.php index 874d955f10097..64e8889068d22 100644 --- a/src/Symfony/Component/Serializer/Annotation/SerializedName.php +++ b/src/Symfony/Component/Serializer/Annotation/SerializedName.php @@ -25,26 +25,11 @@ #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)] final class SerializedName { - /** - * @var string - */ private $serializedName; - /** - * @param string $serializedName - */ - public function __construct($serializedName) + public function __construct(string $serializedName) { - if (\is_array($serializedName)) { - trigger_deprecation('symfony/serializer', '5.3', 'Passing an array as first argument to "%s" is deprecated. Use named arguments instead.', __METHOD__); - - if (!isset($serializedName['value'])) { - throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" should be set.', static::class)); - } - $serializedName = $serializedName['value']; - } - - if (!\is_string($serializedName) || empty($serializedName)) { + if (empty($serializedName)) { throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a non-empty string.', static::class)); } diff --git a/src/Symfony/Component/Serializer/CacheWarmer/CompiledClassMetadataCacheWarmer.php b/src/Symfony/Component/Serializer/CacheWarmer/CompiledClassMetadataCacheWarmer.php index 360640e139723..081bcff674572 100644 --- a/src/Symfony/Component/Serializer/CacheWarmer/CompiledClassMetadataCacheWarmer.php +++ b/src/Symfony/Component/Serializer/CacheWarmer/CompiledClassMetadataCacheWarmer.php @@ -40,7 +40,7 @@ public function __construct(array $classesToCompile, ClassMetadataFactoryInterfa /** * {@inheritdoc} */ - public function warmUp($cacheDir) + public function warmUp(string $cacheDir) { $metadatas = []; diff --git a/src/Symfony/Component/Serializer/Encoder/ChainEncoder.php b/src/Symfony/Component/Serializer/Encoder/ChainEncoder.php index 48722d21c1bcc..0c2a53753dcd4 100644 --- a/src/Symfony/Component/Serializer/Encoder/ChainEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/ChainEncoder.php @@ -35,7 +35,7 @@ public function __construct(array $encoders = []) /** * {@inheritdoc} */ - final public function encode($data, string $format, array $context = []) + final public function encode(mixed $data, string $format, array $context = []) { return $this->getEncoder($format, $context)->encode($data, $format, $context); } diff --git a/src/Symfony/Component/Serializer/Encoder/CsvEncoder.php b/src/Symfony/Component/Serializer/Encoder/CsvEncoder.php index e73c0ae2968e0..8d1f1f99bbc85 100644 --- a/src/Symfony/Component/Serializer/Encoder/CsvEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/CsvEncoder.php @@ -58,7 +58,7 @@ public function __construct(array $defaultContext = []) /** * {@inheritdoc} */ - public function encode($data, string $format, array $context = []) + public function encode(mixed $data, string $format, array $context = []) { $handle = fopen('php://temp,', 'w+'); diff --git a/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php b/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php index 0ce4636be08c3..5b4c5ea4312cb 100644 --- a/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php +++ b/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php @@ -29,7 +29,7 @@ interface EncoderInterface * * @throws UnexpectedValueException */ - public function encode($data, string $format, array $context = []); + public function encode(mixed $data, string $format, array $context = []); /** * Checks whether the serializer can encode to given format. diff --git a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php index d817aa0ecea9f..4da793ffdb047 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php @@ -32,11 +32,9 @@ public function __construct(array $defaultContext = []) } /** - * Encodes PHP data to a JSON string. - * * {@inheritdoc} */ - public function encode($data, string $format, array $context = []) + public function encode(mixed $data, string $format, array $context = []) { $options = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS]; diff --git a/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php b/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php index cf4a89ca1ab5f..c10be44b114fc 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php @@ -32,7 +32,7 @@ public function __construct(JsonEncode $encodingImpl = null, JsonDecode $decodin /** * {@inheritdoc} */ - public function encode($data, string $format, array $context = []) + public function encode(mixed $data, string $format, array $context = []) { return $this->encodingImpl->encode($data, self::FORMAT, $context); } diff --git a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php index 5964cd7a9dec4..7a885e711a7c3 100644 --- a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php @@ -80,7 +80,7 @@ public function __construct(array $defaultContext = []) /** * {@inheritdoc} */ - public function encode($data, string $format, array $context = []) + public function encode(mixed $data, string $format, array $context = []) { $encoderIgnoredNodeTypes = $context[self::ENCODER_IGNORED_NODE_TYPES] ?? $this->defaultContext[self::ENCODER_IGNORED_NODE_TYPES]; $ignorePiNode = \in_array(\XML_PI_NODE, $encoderIgnoredNodeTypes, true); @@ -217,10 +217,7 @@ final protected function appendCData(\DOMNode $node, string $val): bool return true; } - /** - * @param \DOMDocumentFragment $fragment - */ - final protected function appendDocumentFragment(\DOMNode $node, $fragment): bool + final protected function appendDocumentFragment(\DOMNode $node, \DOMDocumentFragment $fragment): bool { if ($fragment instanceof \DOMDocumentFragment) { $node->appendChild($fragment); @@ -357,11 +354,9 @@ private function parseXmlValue(\DOMNode $node, array $context = []) /** * Parse the data and convert it to DOMElements. * - * @param array|object $data - * * @throws NotEncodableValueException */ - private function buildXml(\DOMNode $parentNode, $data, string $xmlRootNodeName = null): bool + private function buildXml(\DOMNode $parentNode, mixed $data, string $xmlRootNodeName = null): bool { $append = true; $removeEmptyTags = $this->context[self::REMOVE_EMPTY_TAGS] ?? $this->defaultContext[self::REMOVE_EMPTY_TAGS] ?? false; @@ -431,10 +426,8 @@ private function buildXml(\DOMNode $parentNode, $data, string $xmlRootNodeName = /** * Selects the type of node to create and appends it to the parent. - * - * @param array|object $data */ - private function appendNode(\DOMNode $parentNode, $data, string $nodeName, string $key = null): bool + private function appendNode(\DOMNode $parentNode, mixed $data, string $nodeName, string $key = null): bool { $node = $this->dom->createElement($nodeName); if (null !== $key) { @@ -462,7 +455,7 @@ private function needsCdataWrapping(string $val): bool * * @throws NotEncodableValueException */ - private function selectNodeType(\DOMNode $node, $val): bool + private function selectNodeType(\DOMNode $node, mixed $val): bool { if (\is_array($val)) { return $this->buildXml($node, $val); diff --git a/src/Symfony/Component/Serializer/Encoder/YamlEncoder.php b/src/Symfony/Component/Serializer/Encoder/YamlEncoder.php index c688c228330d9..651cfc70f3770 100644 --- a/src/Symfony/Component/Serializer/Encoder/YamlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/YamlEncoder.php @@ -54,7 +54,7 @@ public function __construct(Dumper $dumper = null, Parser $parser = null, array /** * {@inheritdoc} */ - public function encode($data, string $format, array $context = []) + public function encode(mixed $data, string $format, array $context = []) { $context = array_merge($this->defaultContext, $context); diff --git a/src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorFromClassMetadata.php b/src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorFromClassMetadata.php index 23554ffda98ab..2e46fecc87e70 100644 --- a/src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorFromClassMetadata.php +++ b/src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorFromClassMetadata.php @@ -44,7 +44,7 @@ public function getMappingForClass(string $class): ?ClassDiscriminatorMapping /** * {@inheritdoc} */ - public function getMappingForMappedObject($object): ?ClassDiscriminatorMapping + public function getMappingForMappedObject(object|string $object): ?ClassDiscriminatorMapping { if ($this->classMetadataFactory->hasMetadataFor($object)) { $metadata = $this->classMetadataFactory->getMetadataFor($object); @@ -65,7 +65,7 @@ public function getMappingForMappedObject($object): ?ClassDiscriminatorMapping /** * {@inheritdoc} */ - public function getTypeForMappedObject($object): ?string + public function getTypeForMappedObject(object|string $object): ?string { if (null === $mapping = $this->getMappingForMappedObject($object)) { return null; @@ -74,7 +74,7 @@ public function getTypeForMappedObject($object): ?string return $mapping->getMappedObjectType($object); } - private function resolveMappingForMappedObject($object) + private function resolveMappingForMappedObject(object|string $object) { $reflectionClass = new \ReflectionClass($object); if ($parentClass = $reflectionClass->getParentClass()) { diff --git a/src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorMapping.php b/src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorMapping.php index 0c314c7ba455d..d38088fad8242 100644 --- a/src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorMapping.php +++ b/src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorMapping.php @@ -47,10 +47,7 @@ public function getClassForType(string $type): ?string return $this->typesMapping[$type] ?? null; } - /** - * @param object|string $object - */ - public function getMappedObjectType($object): ?string + public function getMappedObjectType(object|string $object): ?string { foreach ($this->typesMapping as $type => $typeClass) { if (is_a($object, $typeClass)) { diff --git a/src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorResolverInterface.php b/src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorResolverInterface.php index 22d76fafb0f4c..83a12d845f280 100644 --- a/src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorResolverInterface.php +++ b/src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorResolverInterface.php @@ -20,13 +20,7 @@ interface ClassDiscriminatorResolverInterface { public function getMappingForClass(string $class): ?ClassDiscriminatorMapping; - /** - * @param object|string $object - */ - public function getMappingForMappedObject($object): ?ClassDiscriminatorMapping; + public function getMappingForMappedObject(object|string $object): ?ClassDiscriminatorMapping; - /** - * @param object|string $object - */ - public function getTypeForMappedObject($object): ?string; + public function getTypeForMappedObject(object|string $object): ?string; } diff --git a/src/Symfony/Component/Serializer/Mapping/Factory/CacheClassMetadataFactory.php b/src/Symfony/Component/Serializer/Mapping/Factory/CacheClassMetadataFactory.php index a85bdb1844016..4d1fe154cc5b2 100644 --- a/src/Symfony/Component/Serializer/Mapping/Factory/CacheClassMetadataFactory.php +++ b/src/Symfony/Component/Serializer/Mapping/Factory/CacheClassMetadataFactory.php @@ -43,7 +43,7 @@ public function __construct(ClassMetadataFactoryInterface $decorated, CacheItemP /** * {@inheritdoc} */ - public function getMetadataFor($value) + public function getMetadataFor(string|object $value) { $class = $this->getClass($value); @@ -67,7 +67,7 @@ public function getMetadataFor($value) /** * {@inheritdoc} */ - public function hasMetadataFor($value) + public function hasMetadataFor(mixed $value) { return $this->decorated->hasMetadataFor($value); } diff --git a/src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactory.php b/src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactory.php index b55c070fb8ae2..5516e7eea28a2 100644 --- a/src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactory.php +++ b/src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactory.php @@ -38,7 +38,7 @@ public function __construct(LoaderInterface $loader) /** * {@inheritdoc} */ - public function getMetadataFor($value) + public function getMetadataFor(string|object $value) { $class = $this->getClass($value); @@ -67,7 +67,7 @@ public function getMetadataFor($value) /** * {@inheritdoc} */ - public function hasMetadataFor($value) + public function hasMetadataFor(mixed $value) { return \is_object($value) || (\is_string($value) && (class_exists($value) || interface_exists($value, false))); } diff --git a/src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactoryInterface.php b/src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactoryInterface.php index 7ef91a82318c6..5d0cfeacdd455 100644 --- a/src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactoryInterface.php +++ b/src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactoryInterface.php @@ -34,20 +34,16 @@ interface ClassMetadataFactoryInterface * {@link \Symfony\Component\Serializer\Mapping\Loader\LoaderInterface::loadClassMetadata()} method for further * configuration. At last, the new object is returned. * - * @param string|object $value - * * @return ClassMetadataInterface * * @throws InvalidArgumentException */ - public function getMetadataFor($value); + public function getMetadataFor(string|object $value); /** * Checks if class has metadata. * - * @param mixed $value - * * @return bool */ - public function hasMetadataFor($value); + public function hasMetadataFor(mixed $value); } diff --git a/src/Symfony/Component/Serializer/Mapping/Factory/ClassResolverTrait.php b/src/Symfony/Component/Serializer/Mapping/Factory/ClassResolverTrait.php index 0a65da5d53584..05ce80922c859 100644 --- a/src/Symfony/Component/Serializer/Mapping/Factory/ClassResolverTrait.php +++ b/src/Symfony/Component/Serializer/Mapping/Factory/ClassResolverTrait.php @@ -25,11 +25,9 @@ trait ClassResolverTrait /** * Gets a class name for a given class or instance. * - * @param object|string $value - * * @throws InvalidArgumentException If the class does not exist */ - private function getClass($value): string + private function getClass(object|string $value): string { if (\is_string($value)) { if (!class_exists($value) && !interface_exists($value, false)) { @@ -39,10 +37,6 @@ private function getClass($value): string return ltrim($value, '\\'); } - if (!\is_object($value)) { - throw new InvalidArgumentException(sprintf('Cannot create metadata for non-objects. Got: "%s".', get_debug_type($value))); - } - return \get_class($value); } } diff --git a/src/Symfony/Component/Serializer/Mapping/Factory/CompiledClassMetadataFactory.php b/src/Symfony/Component/Serializer/Mapping/Factory/CompiledClassMetadataFactory.php index 17daf9e66d2e8..1753cc584f5d7 100644 --- a/src/Symfony/Component/Serializer/Mapping/Factory/CompiledClassMetadataFactory.php +++ b/src/Symfony/Component/Serializer/Mapping/Factory/CompiledClassMetadataFactory.php @@ -44,7 +44,7 @@ public function __construct(string $compiledClassMetadataFile, ClassMetadataFact /** * {@inheritdoc} */ - public function getMetadataFor($value) + public function getMetadataFor(string|object $value) { $className = \is_object($value) ? \get_class($value) : $value; @@ -72,7 +72,7 @@ public function getMetadataFor($value) /** * {@inheritdoc} */ - public function hasMetadataFor($value) + public function hasMetadataFor(mixed $value) { $className = \is_object($value) ? \get_class($value) : $value; diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php index a8698baaf0b43..0aec8c6f98d4e 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php @@ -202,11 +202,9 @@ protected function isCircularReference(object $object, array &$context) * * @final * - * @return mixed - * * @throws CircularReferenceException */ - protected function handleCircularReference(object $object, string $format = null, array $context = []) + protected function handleCircularReference(object $object, string $format = null, array $context = []): mixed { $circularReferenceHandler = $context[self::CIRCULAR_REFERENCE_HANDLER] ?? $this->defaultContext[self::CIRCULAR_REFERENCE_HANDLER]; if ($circularReferenceHandler) { @@ -219,14 +217,13 @@ protected function handleCircularReference(object $object, string $format = null /** * Gets attributes to normalize using groups. * - * @param string|object $classOrObject - * @param bool $attributesAsString If false, return an array of {@link AttributeMetadataInterface} + * @param bool $attributesAsString If false, return an array of {@link AttributeMetadataInterface} * * @throws LogicException if the 'allow_extra_attributes' context variable is false and no class metadata factory is provided * * @return string[]|AttributeMetadataInterface[]|bool */ - protected function getAllowedAttributes($classOrObject, array $context, bool $attributesAsString = false) + protected function getAllowedAttributes(string|object $classOrObject, array $context, bool $attributesAsString = false) { $allowExtraAttributes = $context[self::ALLOW_EXTRA_ATTRIBUTES] ?? $this->defaultContext[self::ALLOW_EXTRA_ATTRIBUTES]; if (!$this->classMetadataFactory) { @@ -274,11 +271,9 @@ protected function getGroups(array $context): array /** * Is this attribute allowed? * - * @param object|string $classOrObject - * * @return bool */ - protected function isAllowedAttribute($classOrObject, string $attribute, string $format = null, array $context = []) + protected function isAllowedAttribute(object|string $classOrObject, string $attribute, string $format = null, array $context = []) { $ignoredAttributes = $context[self::IGNORED_ATTRIBUTES] ?? $this->defaultContext[self::IGNORED_ATTRIBUTES]; if (\in_array($attribute, $ignoredAttributes)) { @@ -302,11 +297,9 @@ protected function isAllowedAttribute($classOrObject, string $attribute, string * Normalizes the given data to an array. It's particularly useful during * the denormalization process. * - * @param object|array $data - * * @return array */ - protected function prepareForDenormalization($data) + protected function prepareForDenormalization(object|array|null $data) { return (array) $data; } @@ -315,11 +308,9 @@ protected function prepareForDenormalization($data) * Returns the method to use to construct an object. This method must be either * the object constructor or static. * - * @param array|bool $allowedAttributes - * * @return \ReflectionMethod|null */ - protected function getConstructor(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes) + protected function getConstructor(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, array|bool $allowedAttributes) { return $reflectionClass->getConstructor(); } @@ -332,14 +323,12 @@ protected function getConstructor(array &$data, string $class, array &$context, * is removed from the context before being returned to avoid side effects * when recursively normalizing an object graph. * - * @param array|bool $allowedAttributes - * * @return object * * @throws RuntimeException * @throws MissingConstructorArgumentsException */ - protected function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, string $format = null) + protected function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, array|bool $allowedAttributes, string $format = null) { if (null !== $object = $this->extractObjectToPopulate($class, $context, self::OBJECT_TO_POPULATE)) { unset($context[self::OBJECT_TO_POPULATE]); @@ -416,7 +405,7 @@ protected function instantiateObject(array &$data, string $class, array &$contex /** * @internal */ - protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, string $parameterName, $parameterData, array $context, string $format = null) + protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, string $parameterName, mixed $parameterData, array $context, string $format = null): mixed { try { if (($parameterType = $parameter->getType()) instanceof \ReflectionNamedType && !$parameterType->isBuiltin()) { diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php index e629189c47f06..54afeb93e54c6 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php @@ -125,7 +125,7 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory /** * {@inheritdoc} */ - public function supportsNormalization($data, string $format = null) + public function supportsNormalization(mixed $data, string $format = null) { return \is_object($data) && !$data instanceof \Traversable; } @@ -133,7 +133,7 @@ public function supportsNormalization($data, string $format = null) /** * {@inheritdoc} */ - public function normalize($object, string $format = null, array $context = []) + public function normalize(mixed $object, string $format = null, array $context = []) { if (!isset($context['cache_key'])) { $context['cache_key'] = $this->getCacheKey($format, $context); @@ -217,7 +217,7 @@ public function normalize($object, string $format = null, array $context = []) /** * Computes the normalization context merged with current one. Metadata always wins over global context, as more specific. */ - private function getAttributeNormalizationContext($object, string $attribute, array $context): array + private function getAttributeNormalizationContext(object $object, string $attribute, array $context): array { if (null === $metadata = $this->getAttributeMetadata($object, $attribute)) { return $context; @@ -238,7 +238,7 @@ private function getAttributeDenormalizationContext(string $class, string $attri return array_merge($context, $metadata->getDenormalizationContextForGroups($this->getGroups($context))); } - private function getAttributeMetadata($objectOrClass, string $attribute): ?AttributeMetadataInterface + private function getAttributeMetadata(object|string $objectOrClass, string $attribute): ?AttributeMetadataInterface { if (!$this->classMetadataFactory) { return null; @@ -250,7 +250,7 @@ private function getAttributeMetadata($objectOrClass, string $attribute): ?Attri /** * {@inheritdoc} */ - protected function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, string $format = null) + protected function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, array|bool $allowedAttributes, string $format = null) { if ($this->classDiscriminatorResolver && $mapping = $this->classDiscriminatorResolver->getMappingForClass($class)) { if (!isset($data[$mapping->getTypeProperty()])) { @@ -324,7 +324,7 @@ abstract protected function getAttributeValue(object $object, string $attribute, /** * {@inheritdoc} */ - public function supportsDenormalization($data, string $type, string $format = null) + public function supportsDenormalization(mixed $data, string $type, string $format = null) { return class_exists($type) || (interface_exists($type, false) && $this->classDiscriminatorResolver && null !== $this->classDiscriminatorResolver->getMappingForClass($type)); } @@ -332,7 +332,7 @@ public function supportsDenormalization($data, string $type, string $format = nu /** * {@inheritdoc} */ - public function denormalize($data, string $type, string $format = null, array $context = []) + public function denormalize(mixed $data, string $type, string $format = null, array $context = []) { if (!isset($context['cache_key'])) { $context['cache_key'] = $this->getCacheKey($format, $context); @@ -386,19 +386,15 @@ public function denormalize($data, string $type, string $format = null, array $c /** * Sets attribute value. */ - abstract protected function setAttributeValue(object $object, string $attribute, $value, string $format = null, array $context = []); + abstract protected function setAttributeValue(object $object, string $attribute, mixed $value, string $format = null, array $context = []); /** * Validates the submitted data and denormalizes it. * - * @param mixed $data - * - * @return mixed - * * @throws NotNormalizableValueException * @throws LogicException */ - private function validateAndDenormalize(string $currentClass, string $attribute, $data, ?string $format, array $context) + private function validateAndDenormalize(string $currentClass, string $attribute, mixed $data, ?string $format, array $context): mixed { if (null === $types = $this->getTypes($currentClass, $attribute)) { return $data; @@ -534,7 +530,7 @@ private function validateAndDenormalize(string $currentClass, string $attribute, /** * @internal */ - protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, string $parameterName, $parameterData, array $context, string $format = null) + protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, string $parameterName, mixed $parameterData, array $context, string $format = null): mixed { if ($parameter->isVariadic() || null === $this->propertyTypeExtractor || null === $this->propertyTypeExtractor->getTypes($class->getName(), $parameterName)) { return parent::denormalizeParameter($class, $parameter, $parameterName, $parameterData, $context, $format); @@ -582,10 +578,8 @@ private function getTypes(string $currentClass, string $attribute): ?array /** * Sets an attribute and apply the name converter if necessary. - * - * @param mixed $attributeValue */ - private function updateData(array $data, string $attribute, $attributeValue, string $class, ?string $format, array $context): array + private function updateData(array $data, string $attribute, mixed $attributeValue, string $class, ?string $format, array $context): array { if (null === $attributeValue && ($context[self::SKIP_NULL_VALUES] ?? $this->defaultContext[self::SKIP_NULL_VALUES] ?? false)) { return $data; @@ -653,10 +647,8 @@ protected function createChildContext(array $parentContext, string $attribute, ? * Builds the cache key for the attributes cache. * * The key must be different for every option in the context that could change which attributes should be handled. - * - * @return bool|string */ - private function getCacheKey(?string $format, array $context) + private function getCacheKey(?string $format, array $context): bool|string { foreach ($context[self::EXCLUDE_FROM_CACHE_KEY] ?? $this->defaultContext[self::EXCLUDE_FROM_CACHE_KEY] as $key) { unset($context[$key]); diff --git a/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php index 77c746c752282..332f4e5a6e323 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php @@ -34,7 +34,7 @@ class ArrayDenormalizer implements ContextAwareDenormalizerInterface, Denormaliz * * @throws NotNormalizableValueException */ - public function denormalize($data, string $type, string $format = null, array $context = []): array + public function denormalize(mixed $data, string $type, string $format = null, array $context = []): array { if (null === $this->denormalizer) { throw new BadMethodCallException('Please set a denormalizer before calling denormalize()!'); @@ -63,7 +63,7 @@ public function denormalize($data, string $type, string $format = null, array $c /** * {@inheritdoc} */ - public function supportsDenormalization($data, string $type, string $format = null, array $context = []): bool + public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool { if (null === $this->denormalizer) { throw new BadMethodCallException(sprintf('The nested denormalizer needs to be set to allow "%s()" to be used.', __METHOD__)); diff --git a/src/Symfony/Component/Serializer/Normalizer/ConstraintViolationListNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ConstraintViolationListNormalizer.php index 2546ffd0c69d5..3ca313466d18e 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ConstraintViolationListNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/ConstraintViolationListNormalizer.php @@ -33,7 +33,7 @@ class ConstraintViolationListNormalizer implements NormalizerInterface, Cacheabl private $defaultContext; private $nameConverter; - public function __construct($defaultContext = [], NameConverterInterface $nameConverter = null) + public function __construct(array $defaultContext = [], NameConverterInterface $nameConverter = null) { $this->defaultContext = $defaultContext; $this->nameConverter = $nameConverter; @@ -44,7 +44,7 @@ public function __construct($defaultContext = [], NameConverterInterface $nameCo * * @return array */ - public function normalize($object, string $format = null, array $context = []) + public function normalize(mixed $object, string $format = null, array $context = []) { if (\array_key_exists(self::PAYLOAD_FIELDS, $context)) { $payloadFieldsToSerialize = $context[self::PAYLOAD_FIELDS]; @@ -109,7 +109,7 @@ public function normalize($object, string $format = null, array $context = []) /** * {@inheritdoc} */ - public function supportsNormalization($data, string $format = null) + public function supportsNormalization(mixed $data, string $format = null) { return $data instanceof ConstraintViolationListInterface; } diff --git a/src/Symfony/Component/Serializer/Normalizer/ContextAwareDenormalizerInterface.php b/src/Symfony/Component/Serializer/Normalizer/ContextAwareDenormalizerInterface.php index c875de1b5287a..b69e9c540410b 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ContextAwareDenormalizerInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/ContextAwareDenormalizerInterface.php @@ -23,5 +23,5 @@ interface ContextAwareDenormalizerInterface extends DenormalizerInterface * * @param array $context options that denormalizers have access to */ - public function supportsDenormalization($data, string $type, string $format = null, array $context = []); + public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []); } diff --git a/src/Symfony/Component/Serializer/Normalizer/ContextAwareNormalizerInterface.php b/src/Symfony/Component/Serializer/Normalizer/ContextAwareNormalizerInterface.php index ff0bb3a21d4fc..50a8d412709dc 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ContextAwareNormalizerInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/ContextAwareNormalizerInterface.php @@ -23,5 +23,5 @@ interface ContextAwareNormalizerInterface extends NormalizerInterface * * @param array $context options that normalizers have access to */ - public function supportsNormalization($data, string $format = null, array $context = []); + public function supportsNormalization(mixed $data, string $format = null, array $context = []); } diff --git a/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php index 44ad1771b6245..8e3a09882bc9f 100644 --- a/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php @@ -25,7 +25,7 @@ class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, Se /** * {@inheritdoc} */ - public function normalize($object, string $format = null, array $context = []) + public function normalize(mixed $object, string $format = null, array $context = []) { return $object->normalize($this->serializer, $format, $context); } @@ -33,7 +33,7 @@ public function normalize($object, string $format = null, array $context = []) /** * {@inheritdoc} */ - public function denormalize($data, string $type, string $format = null, array $context = []) + public function denormalize(mixed $data, string $type, string $format = null, array $context = []) { $object = $this->extractObjectToPopulate($type, $context) ?? new $type(); $object->denormalize($this->serializer, $data, $format, $context); @@ -49,7 +49,7 @@ public function denormalize($data, string $type, string $format = null, array $c * * @return bool */ - public function supportsNormalization($data, string $format = null) + public function supportsNormalization(mixed $data, string $format = null) { return $data instanceof NormalizableInterface; } @@ -63,7 +63,7 @@ public function supportsNormalization($data, string $format = null) * * @return bool */ - public function supportsDenormalization($data, string $type, string $format = null) + public function supportsDenormalization(mixed $data, string $type, string $format = null) { return is_subclass_of($type, DenormalizableInterface::class); } diff --git a/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php index bb866ec9bcc36..4d5aa1cb82a32 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php @@ -50,7 +50,7 @@ public function __construct(MimeTypeGuesserInterface $mimeTypeGuesser = null) * * @return string */ - public function normalize($object, string $format = null, array $context = []) + public function normalize(mixed $object, string $format = null, array $context = []) { if (!$object instanceof \SplFileInfo) { throw new InvalidArgumentException('The object must be an instance of "\SplFileInfo".'); @@ -76,7 +76,7 @@ public function normalize($object, string $format = null, array $context = []) /** * {@inheritdoc} */ - public function supportsNormalization($data, string $format = null) + public function supportsNormalization(mixed $data, string $format = null) { return $data instanceof \SplFileInfo; } @@ -93,7 +93,7 @@ public function supportsNormalization($data, string $format = null) * * @return \SplFileInfo */ - public function denormalize($data, string $type, string $format = null, array $context = []) + public function denormalize(mixed $data, string $type, string $format = null, array $context = []) { if (!preg_match('/^data:([a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}\/[a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}(;[a-z0-9\-]+\=[a-z0-9\-]+)?)?(;base64)?,[a-z0-9\!\$\&\\\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i', $data)) { throw new NotNormalizableValueException('The provided "data:" URI is not valid.'); @@ -122,7 +122,7 @@ public function denormalize($data, string $type, string $format = null, array $c /** * {@inheritdoc} */ - public function supportsDenormalization($data, string $type, string $format = null) + public function supportsDenormalization(mixed $data, string $type, string $format = null) { return isset(self::SUPPORTED_TYPES[$type]); } diff --git a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php index 7a02d182768fc..0bf42f90c6efe 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php @@ -40,7 +40,7 @@ public function __construct(array $defaultContext = []) * * @return string */ - public function normalize($object, string $format = null, array $context = []) + public function normalize(mixed $object, string $format = null, array $context = []) { if (!$object instanceof \DateInterval) { throw new InvalidArgumentException('The object must be an instance of "\DateInterval".'); @@ -52,7 +52,7 @@ public function normalize($object, string $format = null, array $context = []) /** * {@inheritdoc} */ - public function supportsNormalization($data, string $format = null) + public function supportsNormalization(mixed $data, string $format = null) { return $data instanceof \DateInterval; } @@ -73,7 +73,7 @@ public function hasCacheableSupportsMethod(): bool * * @return \DateInterval */ - public function denormalize($data, string $type, string $format = null, array $context = []) + public function denormalize(mixed $data, string $type, string $format = null, array $context = []) { if (!\is_string($data)) { throw new InvalidArgumentException(sprintf('Data expected to be a string, "%s" given.', get_debug_type($data))); @@ -122,7 +122,7 @@ public function denormalize($data, string $type, string $format = null, array $c /** * {@inheritdoc} */ - public function supportsDenormalization($data, string $type, string $format = null) + public function supportsDenormalization(mixed $data, string $type, string $format = null) { return \DateInterval::class === $type; } diff --git a/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php index 19f9efdc0840a..9352e0dc1f9f6 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php @@ -48,7 +48,7 @@ public function __construct(array $defaultContext = []) * * @return string */ - public function normalize($object, string $format = null, array $context = []) + public function normalize(mixed $object, string $format = null, array $context = []) { if (!$object instanceof \DateTimeInterface) { throw new InvalidArgumentException('The object must implement the "\DateTimeInterface".'); @@ -68,7 +68,7 @@ public function normalize($object, string $format = null, array $context = []) /** * {@inheritdoc} */ - public function supportsNormalization($data, string $format = null) + public function supportsNormalization(mixed $data, string $format = null) { return $data instanceof \DateTimeInterface; } @@ -80,7 +80,7 @@ public function supportsNormalization($data, string $format = null) * * @return \DateTimeInterface */ - public function denormalize($data, string $type, string $format = null, array $context = []) + public function denormalize(mixed $data, string $type, string $format = null, array $context = []) { $dateTimeFormat = $context[self::FORMAT_KEY] ?? null; $timezone = $this->getTimezone($context); @@ -111,7 +111,7 @@ public function denormalize($data, string $type, string $format = null, array $c /** * {@inheritdoc} */ - public function supportsDenormalization($data, string $type, string $format = null) + public function supportsDenormalization(mixed $data, string $type, string $format = null) { return isset(self::SUPPORTED_TYPES[$type]); } diff --git a/src/Symfony/Component/Serializer/Normalizer/DateTimeZoneNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateTimeZoneNormalizer.php index af262ebaad70e..d86fd6894da47 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateTimeZoneNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateTimeZoneNormalizer.php @@ -28,7 +28,7 @@ class DateTimeZoneNormalizer implements NormalizerInterface, DenormalizerInterfa * * @return string */ - public function normalize($object, string $format = null, array $context = []) + public function normalize(mixed $object, string $format = null, array $context = []) { if (!$object instanceof \DateTimeZone) { throw new InvalidArgumentException('The object must be an instance of "\DateTimeZone".'); @@ -40,7 +40,7 @@ public function normalize($object, string $format = null, array $context = []) /** * {@inheritdoc} */ - public function supportsNormalization($data, string $format = null) + public function supportsNormalization(mixed $data, string $format = null) { return $data instanceof \DateTimeZone; } @@ -52,7 +52,7 @@ public function supportsNormalization($data, string $format = null) * * @return \DateTimeZone */ - public function denormalize($data, string $type, string $format = null, array $context = []) + public function denormalize(mixed $data, string $type, string $format = null, array $context = []) { if ('' === $data || null === $data) { throw new NotNormalizableValueException('The data is either an empty string or null, you should pass a string that can be parsed as a DateTimeZone.'); @@ -68,7 +68,7 @@ public function denormalize($data, string $type, string $format = null, array $c /** * {@inheritdoc} */ - public function supportsDenormalization($data, string $type, string $format = null) + public function supportsDenormalization(mixed $data, string $type, string $format = null) { return \DateTimeZone::class === $type; } diff --git a/src/Symfony/Component/Serializer/Normalizer/DenormalizableInterface.php b/src/Symfony/Component/Serializer/Normalizer/DenormalizableInterface.php index 05c08112ead21..73cff737727a3 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DenormalizableInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/DenormalizableInterface.php @@ -34,5 +34,5 @@ interface DenormalizableInterface * differently based on different input formats * @param array $context Options for denormalizing */ - public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = []); + public function denormalize(DenormalizerInterface $denormalizer, array|string|int|float|bool $data, string $format = null, array $context = []); } diff --git a/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php b/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php index d903b3912d019..3f44f34c74cc1 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php @@ -42,7 +42,7 @@ interface DenormalizerInterface * @throws RuntimeException Occurs if the class cannot be instantiated * @throws ExceptionInterface Occurs for all the other cases of errors */ - public function denormalize($data, string $type, string $format = null, array $context = []); + public function denormalize(mixed $data, string $type, string $format = null, array $context = []); /** * Checks whether the given class is supported for denormalization by this normalizer. @@ -53,5 +53,5 @@ public function denormalize($data, string $type, string $format = null, array $c * * @return bool */ - public function supportsDenormalization($data, string $type, string $format = null); + public function supportsDenormalization(mixed $data, string $type, string $format = null); } diff --git a/src/Symfony/Component/Serializer/Normalizer/FormErrorNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/FormErrorNormalizer.php index 48399f4e6c068..8bd8a845fc793 100644 --- a/src/Symfony/Component/Serializer/Normalizer/FormErrorNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/FormErrorNormalizer.php @@ -25,7 +25,7 @@ final class FormErrorNormalizer implements NormalizerInterface, CacheableSupport /** * {@inheritdoc} */ - public function normalize($object, $format = null, array $context = []): array + public function normalize(mixed $object, string $format = null, array $context = []): array { $data = [ 'title' => $context[self::TITLE] ?? 'Validation Failed', @@ -44,7 +44,7 @@ public function normalize($object, $format = null, array $context = []): array /** * {@inheritdoc} */ - public function supportsNormalization($data, $format = null): bool + public function supportsNormalization(mixed $data, string $format = null): bool { return $data instanceof FormInterface && $data->isSubmitted() && !$data->isValid(); } diff --git a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php index aacce5092428e..2d3adb8618f8b 100644 --- a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php @@ -39,7 +39,7 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer /** * {@inheritdoc} */ - public function supportsNormalization($data, string $format = null) + public function supportsNormalization(mixed $data, string $format = null) { return parent::supportsNormalization($data, $format) && $this->supports(\get_class($data)); } @@ -47,7 +47,7 @@ public function supportsNormalization($data, string $format = null) /** * {@inheritdoc} */ - public function supportsDenormalization($data, string $type, string $format = null) + public function supportsDenormalization(mixed $data, string $type, string $format = null) { return parent::supportsDenormalization($data, $type, $format) && $this->supports($type); } @@ -146,7 +146,7 @@ protected function getAttributeValue(object $object, string $attribute, string $ /** * {@inheritdoc} */ - protected function setAttributeValue(object $object, string $attribute, $value, string $format = null, array $context = []) + protected function setAttributeValue(object $object, string $attribute, mixed $value, string $format = null, array $context = []) { $setter = 'set'.ucfirst($attribute); $key = \get_class($object).':'.$setter; diff --git a/src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php index f38956c3e3cab..4533ff73819f6 100644 --- a/src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php @@ -24,7 +24,7 @@ class JsonSerializableNormalizer extends AbstractNormalizer /** * {@inheritdoc} */ - public function normalize($object, string $format = null, array $context = []) + public function normalize(mixed $object, string $format = null, array $context = []) { if ($this->isCircularReference($object, $context)) { return $this->handleCircularReference($object); @@ -44,7 +44,7 @@ public function normalize($object, string $format = null, array $context = []) /** * {@inheritdoc} */ - public function supportsNormalization($data, string $format = null) + public function supportsNormalization(mixed $data, string $format = null) { return $data instanceof \JsonSerializable; } @@ -52,7 +52,7 @@ public function supportsNormalization($data, string $format = null) /** * {@inheritdoc} */ - public function supportsDenormalization($data, string $type, string $format = null) + public function supportsDenormalization(mixed $data, string $type, string $format = null) { return false; } @@ -60,7 +60,7 @@ public function supportsDenormalization($data, string $type, string $format = nu /** * {@inheritdoc} */ - public function denormalize($data, string $type, string $format = null, array $context = []) + public function denormalize(mixed $data, string $type, string $format = null, array $context = []) { throw new LogicException(sprintf('Cannot denormalize with "%s".', \JsonSerializable::class)); } diff --git a/src/Symfony/Component/Serializer/Normalizer/MimeMessageNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/MimeMessageNormalizer.php index 0708847bde0e5..14c6b842f4bd6 100644 --- a/src/Symfony/Component/Serializer/Normalizer/MimeMessageNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/MimeMessageNormalizer.php @@ -52,7 +52,7 @@ public function setSerializer(SerializerInterface $serializer) /** * {@inheritdoc} */ - public function normalize($object, string $format = null, array $context = []) + public function normalize(mixed $object, string $format = null, array $context = []) { if ($object instanceof Headers) { $ret = []; @@ -76,7 +76,7 @@ public function normalize($object, string $format = null, array $context = []) /** * {@inheritdoc} */ - public function denormalize($data, string $type, string $format = null, array $context = []) + public function denormalize(mixed $data, string $type, string $format = null, array $context = []) { if (Headers::class === $type) { $ret = []; @@ -100,7 +100,7 @@ public function denormalize($data, string $type, string $format = null, array $c /** * {@inheritdoc} */ - public function supportsNormalization($data, string $format = null) + public function supportsNormalization(mixed $data, string $format = null) { return $data instanceof Message || $data instanceof Headers || $data instanceof HeaderInterface || $data instanceof Address || $data instanceof AbstractPart; } @@ -108,7 +108,7 @@ public function supportsNormalization($data, string $format = null) /** * {@inheritdoc} */ - public function supportsDenormalization($data, string $type, string $format = null) + public function supportsDenormalization(mixed $data, string $type, string $format = null) { return is_a($type, Message::class, true) || Headers::class === $type || AbstractPart::class === $type; } diff --git a/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php b/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php index 653f949548c41..30eeafb47bac7 100644 --- a/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php @@ -36,7 +36,7 @@ interface NormalizerInterface * @throws LogicException Occurs when the normalizer is not called in an expected context * @throws ExceptionInterface Occurs for all the other cases of errors */ - public function normalize($object, string $format = null, array $context = []); + public function normalize(mixed $object, string $format = null, array $context = []); /** * Checks whether the given class is supported for normalization by this normalizer. @@ -46,5 +46,5 @@ public function normalize($object, string $format = null, array $context = []); * * @return bool */ - public function supportsNormalization($data, string $format = null); + public function supportsNormalization(mixed $data, string $format = null); } diff --git a/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php index 458b38f9d9c53..aaa3867b4fbcd 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php @@ -153,7 +153,7 @@ protected function getAttributeValue(object $object, string $attribute, string $ /** * {@inheritdoc} */ - protected function setAttributeValue(object $object, string $attribute, $value, string $format = null, array $context = []) + protected function setAttributeValue(object $object, string $attribute, mixed $value, string $format = null, array $context = []) { try { $this->propertyAccessor->setValue($object, $attribute, $value); @@ -165,7 +165,7 @@ protected function setAttributeValue(object $object, string $attribute, $value, /** * {@inheritdoc} */ - protected function getAllowedAttributes($classOrObject, array $context, bool $attributesAsString = false) + protected function getAllowedAttributes(string|object $classOrObject, array $context, bool $attributesAsString = false) { if (false === $allowedAttributes = parent::getAllowedAttributes($classOrObject, $context, $attributesAsString)) { return false; diff --git a/src/Symfony/Component/Serializer/Normalizer/ProblemNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ProblemNormalizer.php index 6fdd2773a3608..1c7bb755b226a 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ProblemNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/ProblemNormalizer.php @@ -41,7 +41,7 @@ public function __construct(bool $debug = false, array $defaultContext = []) * * @return array */ - public function normalize($object, string $format = null, array $context = []) + public function normalize(mixed $object, string $format = null, array $context = []) { if (!$object instanceof FlattenException) { throw new InvalidArgumentException(sprintf('The object must implement "%s".', FlattenException::class)); @@ -67,7 +67,7 @@ public function normalize($object, string $format = null, array $context = []) /** * {@inheritdoc} */ - public function supportsNormalization($data, string $format = null): bool + public function supportsNormalization(mixed $data, string $format = null): bool { return $data instanceof FlattenException; } diff --git a/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php index 8a0a3efeef72a..ce210f075c3a7 100644 --- a/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php @@ -33,7 +33,7 @@ class PropertyNormalizer extends AbstractObjectNormalizer /** * {@inheritdoc} */ - public function supportsNormalization($data, string $format = null) + public function supportsNormalization(mixed $data, string $format = null) { return parent::supportsNormalization($data, $format) && $this->supports(\get_class($data)); } @@ -41,7 +41,7 @@ public function supportsNormalization($data, string $format = null) /** * {@inheritdoc} */ - public function supportsDenormalization($data, string $type, string $format = null) + public function supportsDenormalization(mixed $data, string $type, string $format = null) { return parent::supportsDenormalization($data, $type, $format) && $this->supports($type); } @@ -76,7 +76,7 @@ private function supports(string $class): bool /** * {@inheritdoc} */ - protected function isAllowedAttribute($classOrObject, string $attribute, string $format = null, array $context = []) + protected function isAllowedAttribute(object|string $classOrObject, string $attribute, string $format = null, array $context = []) { if (!parent::isAllowedAttribute($classOrObject, $attribute, $format, $context)) { return false; @@ -145,7 +145,7 @@ protected function getAttributeValue(object $object, string $attribute, string $ /** * {@inheritdoc} */ - protected function setAttributeValue(object $object, string $attribute, $value, string $format = null, array $context = []) + protected function setAttributeValue(object $object, string $attribute, mixed $value, string $format = null, array $context = []) { try { $reflectionProperty = $this->getReflectionProperty($object, $attribute); @@ -166,11 +166,9 @@ protected function setAttributeValue(object $object, string $attribute, $value, } /** - * @param string|object $classOrObject - * * @throws \ReflectionException */ - private function getReflectionProperty($classOrObject, string $attribute): \ReflectionProperty + private function getReflectionProperty(string|object $classOrObject, string $attribute): \ReflectionProperty { $reflectionClass = new \ReflectionClass($classOrObject); while (true) { diff --git a/src/Symfony/Component/Serializer/Normalizer/UidNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/UidNormalizer.php index 009d334895ee8..8355068930347 100644 --- a/src/Symfony/Component/Serializer/Normalizer/UidNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/UidNormalizer.php @@ -40,7 +40,7 @@ public function __construct(array $defaultContext = []) * * @param AbstractUid $object */ - public function normalize($object, string $format = null, array $context = []) + public function normalize(mixed $object, string $format = null, array $context = []) { switch ($context[self::NORMALIZATION_FORMAT_KEY] ?? $this->defaultContext[self::NORMALIZATION_FORMAT_KEY]) { case self::NORMALIZATION_FORMAT_CANONICAL: @@ -59,7 +59,7 @@ public function normalize($object, string $format = null, array $context = []) /** * {@inheritdoc} */ - public function supportsNormalization($data, string $format = null) + public function supportsNormalization(mixed $data, string $format = null) { return $data instanceof AbstractUid; } @@ -67,7 +67,7 @@ public function supportsNormalization($data, string $format = null) /** * {@inheritdoc} */ - public function denormalize($data, string $type, string $format = null, array $context = []) + public function denormalize(mixed $data, string $type, string $format = null, array $context = []) { try { return Ulid::class === $type ? Ulid::fromString($data) : Uuid::fromString($data); @@ -79,7 +79,7 @@ public function denormalize($data, string $type, string $format = null, array $c /** * {@inheritdoc} */ - public function supportsDenormalization($data, string $type, string $format = null) + public function supportsDenormalization(mixed $data, string $type, string $format = null) { return is_a($type, AbstractUid::class, true); } diff --git a/src/Symfony/Component/Serializer/Normalizer/UnwrappingDenormalizer.php b/src/Symfony/Component/Serializer/Normalizer/UnwrappingDenormalizer.php index 6bc8df80bb3cd..f3531b2360b37 100644 --- a/src/Symfony/Component/Serializer/Normalizer/UnwrappingDenormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/UnwrappingDenormalizer.php @@ -35,7 +35,7 @@ public function __construct(PropertyAccessorInterface $propertyAccessor = null) /** * {@inheritdoc} */ - public function denormalize($data, $class, string $format = null, array $context = []) + public function denormalize(mixed $data, string $class, string $format = null, array $context = []) { $propertyPath = $context[self::UNWRAP_PATH]; $context['unwrapped'] = true; @@ -54,7 +54,7 @@ public function denormalize($data, $class, string $format = null, array $context /** * {@inheritdoc} */ - public function supportsDenormalization($data, $type, string $format = null, array $context = []) + public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []) { return \array_key_exists(self::UNWRAP_PATH, $context) && !isset($context['unwrapped']); } diff --git a/src/Symfony/Component/Serializer/Serializer.php b/src/Symfony/Component/Serializer/Serializer.php index 686e831a73365..bc535e4aa7c65 100644 --- a/src/Symfony/Component/Serializer/Serializer.php +++ b/src/Symfony/Component/Serializer/Serializer.php @@ -117,7 +117,7 @@ public function __construct(array $normalizers = [], array $encoders = []) /** * {@inheritdoc} */ - final public function serialize($data, string $format, array $context = []): string + final public function serialize(mixed $data, string $format, array $context = []): string { if (!$this->supportsEncoding($format, $context)) { throw new NotEncodableValueException(sprintf('Serialization for the format "%s" is not supported.', $format)); @@ -133,7 +133,7 @@ final public function serialize($data, string $format, array $context = []): str /** * {@inheritdoc} */ - final public function deserialize($data, string $type, string $format, array $context = []) + final public function deserialize(mixed $data, string $type, string $format, array $context = []) { if (!$this->supportsDecoding($format, $context)) { throw new NotEncodableValueException(sprintf('Deserialization for the format "%s" is not supported.', $format)); @@ -147,7 +147,7 @@ final public function deserialize($data, string $type, string $format, array $co /** * {@inheritdoc} */ - public function normalize($data, string $format = null, array $context = []) + public function normalize(mixed $data, string $format = null, array $context = []) { // If a normalizer supports the given data, use it if ($normalizer = $this->getNormalizer($data, $format, $context)) { @@ -187,7 +187,7 @@ public function normalize($data, string $format = null, array $context = []) * * @throws NotNormalizableValueException */ - public function denormalize($data, string $type, string $format = null, array $context = []) + public function denormalize(mixed $data, string $type, string $format = null, array $context = []) { $normalizer = $this->getDenormalizer($data, $type, $format, $context); @@ -214,7 +214,7 @@ public function denormalize($data, string $type, string $format = null, array $c /** * {@inheritdoc} */ - public function supportsNormalization($data, string $format = null, array $context = []) + public function supportsNormalization(mixed $data, string $format = null, array $context = []) { return null !== $this->getNormalizer($data, $format, $context); } @@ -222,7 +222,7 @@ public function supportsNormalization($data, string $format = null, array $conte /** * {@inheritdoc} */ - public function supportsDenormalization($data, string $type, string $format = null, array $context = []) + public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []) { return isset(self::SCALAR_TYPES[$type]) || null !== $this->getDenormalizer($data, $type, $format, $context); } @@ -234,7 +234,7 @@ public function supportsDenormalization($data, string $type, string $format = nu * @param string $format Format name, present to give the option to normalizers to act differently based on formats * @param array $context Options available to the normalizer */ - private function getNormalizer($data, ?string $format, array $context): ?NormalizerInterface + private function getNormalizer(mixed $data, ?string $format, array $context): ?NormalizerInterface { $type = \is_object($data) ? \get_class($data) : 'native-'.\gettype($data); @@ -273,7 +273,7 @@ private function getNormalizer($data, ?string $format, array $context): ?Normali * @param string $format Format name, present to give the option to normalizers to act differently based on formats * @param array $context Options available to the denormalizer */ - private function getDenormalizer($data, string $class, ?string $format, array $context): ?DenormalizerInterface + private function getDenormalizer(mixed $data, string $class, ?string $format, array $context): ?DenormalizerInterface { if (!isset($this->denormalizerCache[$format][$class])) { $this->denormalizerCache[$format][$class] = []; @@ -305,7 +305,7 @@ private function getDenormalizer($data, string $class, ?string $format, array $c /** * {@inheritdoc} */ - final public function encode($data, string $format, array $context = []) + final public function encode(mixed $data, string $format, array $context = []) { return $this->encoder->encode($data, $format, $context); } diff --git a/src/Symfony/Component/Serializer/SerializerInterface.php b/src/Symfony/Component/Serializer/SerializerInterface.php index 96e144e90e992..9e9a3d3b76196 100644 --- a/src/Symfony/Component/Serializer/SerializerInterface.php +++ b/src/Symfony/Component/Serializer/SerializerInterface.php @@ -25,7 +25,7 @@ interface SerializerInterface * * @return string */ - public function serialize($data, string $format, array $context = []); + public function serialize(mixed $data, string $format, array $context = []); /** * Deserializes data into the given type. @@ -34,5 +34,5 @@ public function serialize($data, string $format, array $context = []); * * @return mixed */ - public function deserialize($data, string $type, string $format, array $context = []); + public function deserialize(mixed $data, string $type, string $format, array $context = []); } diff --git a/src/Symfony/Component/Serializer/Tests/Annotation/DiscriminatorMapTest.php b/src/Symfony/Component/Serializer/Tests/Annotation/DiscriminatorMapTest.php index 00001112529dd..6a93c4e54efc9 100644 --- a/src/Symfony/Component/Serializer/Tests/Annotation/DiscriminatorMapTest.php +++ b/src/Symfony/Component/Serializer/Tests/Annotation/DiscriminatorMapTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Serializer\Tests\Annotation; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\Serializer\Annotation\DiscriminatorMap; use Symfony\Component\Serializer\Exception\InvalidArgumentException; @@ -21,8 +20,6 @@ */ class DiscriminatorMapTest extends TestCase { - use ExpectDeprecationTrait; - public function testGetTypePropertyAndMapping() { $annotation = new DiscriminatorMap(...['typeProperty' => 'type', 'mapping' => [ @@ -37,75 +34,15 @@ public function testGetTypePropertyAndMapping() ], $annotation->getMapping()); } - /** - * @group legacy - */ - public function testGetTypePropertyAndMappingLegacy() - { - $this->expectDeprecation('Since symfony/serializer 5.3: Passing an array as first argument to "Symfony\Component\Serializer\Annotation\DiscriminatorMap::__construct" is deprecated. Use named arguments instead.'); - $annotation = new DiscriminatorMap(['typeProperty' => 'type', 'mapping' => [ - 'foo' => 'FooClass', - 'bar' => 'BarClass', - ]]); - - $this->assertEquals('type', $annotation->getTypeProperty()); - $this->assertEquals([ - 'foo' => 'FooClass', - 'bar' => 'BarClass', - ], $annotation->getMapping()); - } - - /** - * @group legacy - */ - public function testExceptionWithoutTypeProperty() - { - $this->expectException(InvalidArgumentException::class); - new DiscriminatorMap(['mapping' => ['foo' => 'FooClass']]); - } - public function testExceptionWithEmptyTypeProperty() { $this->expectException(InvalidArgumentException::class); new DiscriminatorMap(...['typeProperty' => '', 'mapping' => ['foo' => 'FooClass']]); } - /** - * @group legacy - */ - public function testExceptionWithEmptyTypePropertyLegacy() - { - $this->expectException(InvalidArgumentException::class); - new DiscriminatorMap(['typeProperty' => '', 'mapping' => ['foo' => 'FooClass']]); - } - - public function testExceptionWithoutMappingProperty() - { - $this->expectException(InvalidArgumentException::class); - new DiscriminatorMap(...['typeProperty' => 'type']); - } - - /** - * @group legacy - */ - public function testExceptionWithoutMappingPropertyLegacy() - { - $this->expectException(InvalidArgumentException::class); - new DiscriminatorMap(['typeProperty' => 'type']); - } - public function testExceptionWitEmptyMappingProperty() { $this->expectException(InvalidArgumentException::class); new DiscriminatorMap(...['typeProperty' => 'type', 'mapping' => []]); } - - /** - * @group legacy - */ - public function testExceptionWitEmptyMappingPropertyLegacy() - { - $this->expectException(InvalidArgumentException::class); - new DiscriminatorMap(['typeProperty' => 'type', 'mapping' => []]); - } } diff --git a/src/Symfony/Component/Serializer/Tests/Annotation/GroupsTest.php b/src/Symfony/Component/Serializer/Tests/Annotation/GroupsTest.php index 890ab86c49f59..2e3823ba660ed 100644 --- a/src/Symfony/Component/Serializer/Tests/Annotation/GroupsTest.php +++ b/src/Symfony/Component/Serializer/Tests/Annotation/GroupsTest.php @@ -26,24 +26,12 @@ public function testEmptyGroupsParameter() new Groups([]); } - /** - * @group legacy - */ public function testEmptyGroupsParameterLegacy() { $this->expectException(InvalidArgumentException::class); new Groups(['value' => []]); } - /** - * @group legacy - */ - public function testNotAnArrayGroupsParameter() - { - $this->expectException(InvalidArgumentException::class); - new Groups(['value' => 12]); - } - public function testInvalidGroupsParameter() { $this->expectException(InvalidArgumentException::class); @@ -58,29 +46,9 @@ public function testGroupsParameters() $this->assertEquals($validData, $groups->getGroups()); } - /** - * @group legacy - */ - public function testGroupsParametersLegacy() - { - $validData = ['a', 'b']; - - $groups = new Groups(['value' => $validData]); - $this->assertEquals($validData, $groups->getGroups()); - } - public function testSingleGroup() { $groups = new Groups('a'); $this->assertEquals(['a'], $groups->getGroups()); } - - /** - * @group legacy - */ - public function testSingleGroupLegacy() - { - $groups = new Groups(['value' => 'a']); - $this->assertEquals(['a'], $groups->getGroups()); - } } diff --git a/src/Symfony/Component/Serializer/Tests/Annotation/MaxDepthTest.php b/src/Symfony/Component/Serializer/Tests/Annotation/MaxDepthTest.php index 3d3355e16ae41..887e1dac3f707 100644 --- a/src/Symfony/Component/Serializer/Tests/Annotation/MaxDepthTest.php +++ b/src/Symfony/Component/Serializer/Tests/Annotation/MaxDepthTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Serializer\Tests\Annotation; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\Serializer\Annotation\MaxDepth; use Symfony\Component\Serializer\Exception\InvalidArgumentException; @@ -21,36 +20,11 @@ */ class MaxDepthTest extends TestCase { - use ExpectDeprecationTrait; - - /** - * @group legacy - */ - public function testNotSetMaxDepthParameter() - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Parameter of annotation "Symfony\Component\Serializer\Annotation\MaxDepth" should be set.'); - new MaxDepth([]); - } - - public function provideInvalidValues() - { - return [ - [''], - ['foo'], - ['1'], - [0], - ]; - } - - /** - * @dataProvider provideInvalidValues - */ - public function testNotAnIntMaxDepthParameter($value) + public function testNotAnIntMaxDepthParameter() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Parameter of annotation "Symfony\Component\Serializer\Annotation\MaxDepth" must be a positive integer.'); - new MaxDepth($value); + new MaxDepth(0); } public function testMaxDepthParameters() @@ -58,15 +32,4 @@ public function testMaxDepthParameters() $maxDepth = new MaxDepth(3); $this->assertEquals(3, $maxDepth->getMaxDepth()); } - - /** - * @group legacy - */ - public function testMaxDepthParametersLegacy() - { - $this->expectDeprecation('Since symfony/serializer 5.3: Passing an array as first argument to "Symfony\Component\Serializer\Annotation\MaxDepth::__construct" is deprecated. Use named arguments instead.'); - - $maxDepth = new MaxDepth(['value' => 3]); - $this->assertEquals(3, $maxDepth->getMaxDepth()); - } } diff --git a/src/Symfony/Component/Serializer/Tests/Annotation/SerializedNameTest.php b/src/Symfony/Component/Serializer/Tests/Annotation/SerializedNameTest.php index 8ea70a67444a1..54a1fce3e25fd 100644 --- a/src/Symfony/Component/Serializer/Tests/Annotation/SerializedNameTest.php +++ b/src/Symfony/Component/Serializer/Tests/Annotation/SerializedNameTest.php @@ -23,16 +23,6 @@ class SerializedNameTest extends TestCase { use ExpectDeprecationTrait; - /** - * @group legacy - */ - public function testNotSetSerializedNameParameter() - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Parameter of annotation "Symfony\Component\Serializer\Annotation\SerializedName" should be set.'); - new SerializedName([]); - } - public function provideInvalidValues(): array { return [ @@ -57,15 +47,4 @@ public function testSerializedNameParameters() $maxDepth = new SerializedName('foo'); $this->assertEquals('foo', $maxDepth->getSerializedName()); } - - /** - * @group legacy - */ - public function testSerializedNameParametersLegacy() - { - $this->expectDeprecation('Since symfony/serializer 5.3: Passing an array as first argument to "Symfony\Component\Serializer\Annotation\SerializedName::__construct" is deprecated. Use named arguments instead.'); - - $maxDepth = new SerializedName(['value' => 'foo']); - $this->assertEquals('foo', $maxDepth->getSerializedName()); - } } diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractNormalizerDummy.php b/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractNormalizerDummy.php index ae3b411b31186..724dff9a7d288 100644 --- a/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractNormalizerDummy.php +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractNormalizerDummy.php @@ -23,7 +23,7 @@ class AbstractNormalizerDummy extends AbstractNormalizer /** * {@inheritdoc} */ - public function getAllowedAttributes($classOrObject, array $context, bool $attributesAsString = false) + public function getAllowedAttributes(string|object $classOrObject, array $context, bool $attributesAsString = false) { return parent::getAllowedAttributes($classOrObject, $context, $attributesAsString); } @@ -31,14 +31,14 @@ public function getAllowedAttributes($classOrObject, array $context, bool $attri /** * {@inheritdoc} */ - public function normalize($object, string $format = null, array $context = []) + public function normalize(mixed $object, string $format = null, array $context = []) { } /** * {@inheritdoc} */ - public function supportsNormalization($data, string $format = null): bool + public function supportsNormalization(mixed $data, string $format = null): bool { return true; } @@ -46,14 +46,14 @@ public function supportsNormalization($data, string $format = null): bool /** * {@inheritdoc} */ - public function denormalize($data, string $type, string $format = null, array $context = []) + public function denormalize(mixed $data, string $type, string $format = null, array $context = []) { } /** * {@inheritdoc} */ - public function supportsDenormalization($data, string $type, string $format = null): bool + public function supportsDenormalization(mixed $data, string $type, string $format = null): bool { return true; } diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/DenormalizableDummy.php b/src/Symfony/Component/Serializer/Tests/Fixtures/DenormalizableDummy.php index e7c03e3d8ec0c..bbf54bd5f7055 100644 --- a/src/Symfony/Component/Serializer/Tests/Fixtures/DenormalizableDummy.php +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/DenormalizableDummy.php @@ -16,7 +16,7 @@ class DenormalizableDummy implements DenormalizableInterface { - public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = []) + public function denormalize(DenormalizerInterface $denormalizer, array|string|int|float|bool $data, string $format = null, array $context = []) { } } diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/Dummy.php b/src/Symfony/Component/Serializer/Tests/Fixtures/Dummy.php index da0400593d254..afd8ed75c5af1 100644 --- a/src/Symfony/Component/Serializer/Tests/Fixtures/Dummy.php +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/Dummy.php @@ -33,7 +33,7 @@ public function normalize(NormalizerInterface $normalizer, string $format = null ]; } - public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = []) + public function denormalize(DenormalizerInterface $denormalizer, array|string|int|float|bool $data, string $format = null, array $context = []) { $this->foo = $data['foo']; $this->bar = $data['bar']; diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/NormalizableTraversableDummy.php b/src/Symfony/Component/Serializer/Tests/Fixtures/NormalizableTraversableDummy.php index 55b4402b076fa..aed3a20c0d3df 100644 --- a/src/Symfony/Component/Serializer/Tests/Fixtures/NormalizableTraversableDummy.php +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/NormalizableTraversableDummy.php @@ -26,7 +26,7 @@ public function normalize(NormalizerInterface $normalizer, string $format = null ]; } - public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = []) + public function denormalize(DenormalizerInterface $denormalizer, array|string|int|float|bool $data, string $format = null, array $context = []) { return [ 'foo' => 'denormalizedFoo', diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/ScalarDummy.php b/src/Symfony/Component/Serializer/Tests/Fixtures/ScalarDummy.php index ffe4ee65859a2..1afbbbd8076ae 100644 --- a/src/Symfony/Component/Serializer/Tests/Fixtures/ScalarDummy.php +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/ScalarDummy.php @@ -26,7 +26,7 @@ public function normalize(NormalizerInterface $normalizer, string $format = null return 'xml' === $format ? $this->xmlFoo : $this->foo; } - public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = []) + public function denormalize(DenormalizerInterface $denormalizer, array|string|int|float|bool $data, string $format = null, array $context = []) { if ('xml' === $format) { $this->xmlFoo = $data; diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/StaticConstructorNormalizer.php b/src/Symfony/Component/Serializer/Tests/Fixtures/StaticConstructorNormalizer.php index 10398f4fc271f..209a07d2c2fb8 100644 --- a/src/Symfony/Component/Serializer/Tests/Fixtures/StaticConstructorNormalizer.php +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/StaticConstructorNormalizer.php @@ -21,7 +21,7 @@ class StaticConstructorNormalizer extends ObjectNormalizer /** * {@inheritdoc} */ - protected function getConstructor(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes): ?\ReflectionMethod + protected function getConstructor(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, array|bool $allowedAttributes): ?\ReflectionMethod { if (is_a($class, StaticConstructorDummy::class, true)) { return new \ReflectionMethod($class, 'create'); diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/UnwrappinDenormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/UnwrappinDenormalizerTest.php index 8d282656504fb..25063b8620d90 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/UnwrappinDenormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/UnwrappinDenormalizerTest.php @@ -34,9 +34,9 @@ protected function setUp(): void public function testSupportsNormalization() { - $this->assertTrue($this->denormalizer->supportsDenormalization([], new \stdClass(), 'any', [UnwrappingDenormalizer::UNWRAP_PATH => '[baz][inner]'])); - $this->assertFalse($this->denormalizer->supportsDenormalization([], new \stdClass(), 'any', [UnwrappingDenormalizer::UNWRAP_PATH => '[baz][inner]', 'unwrapped' => true])); - $this->assertFalse($this->denormalizer->supportsDenormalization([], new \stdClass(), 'any', [])); + $this->assertTrue($this->denormalizer->supportsDenormalization([], 'stdClass', 'any', [UnwrappingDenormalizer::UNWRAP_PATH => '[baz][inner]'])); + $this->assertFalse($this->denormalizer->supportsDenormalization([], 'stdClass', 'any', [UnwrappingDenormalizer::UNWRAP_PATH => '[baz][inner]', 'unwrapped' => true])); + $this->assertFalse($this->denormalizer->supportsDenormalization([], 'stdClass', 'any', [])); } public function testDenormalize()