From 68b588cf4578e6dd83303ab89b171e537e1b7364 Mon Sep 17 00:00:00 2001 From: Amrouche Hamza Date: Thu, 27 Jun 2019 18:57:47 +0200 Subject: [PATCH] [Serializer] [5.0] Add type-hints to serializer interface --- .../Component/Serializer/Encoder/ChainDecoder.php | 4 ++-- .../Component/Serializer/Encoder/ChainEncoder.php | 9 +++------ .../Encoder/ContextAwareDecoderInterface.php | 2 +- .../Encoder/ContextAwareEncoderInterface.php | 2 +- .../Component/Serializer/Encoder/CsvEncoder.php | 4 ++-- .../Serializer/Encoder/DecoderInterface.php | 4 ++-- .../Serializer/Encoder/EncoderInterface.php | 4 ++-- .../Component/Serializer/Encoder/JsonDecode.php | 4 ++-- .../Component/Serializer/Encoder/JsonEncode.php | 4 ++-- .../Component/Serializer/Encoder/JsonEncoder.php | 8 ++++---- .../Component/Serializer/Encoder/XmlEncoder.php | 8 ++++---- .../Component/Serializer/Encoder/YamlEncoder.php | 8 ++++---- .../Mapping/AttributeMetadataInterface.php | 4 ++-- .../CamelCaseToSnakeCaseNameConverter.php | 4 ++-- .../NameConverter/NameConverterInterface.php | 4 ++-- .../Normalizer/AbstractObjectNormalizer.php | 14 +++++++------- .../ContextAwareDenormalizerInterface.php | 2 +- .../Normalizer/ContextAwareNormalizerInterface.php | 2 +- .../Serializer/Normalizer/CustomNormalizer.php | 8 ++++---- .../Serializer/Normalizer/DataUriNormalizer.php | 8 ++++---- .../Normalizer/DateIntervalNormalizer.php | 8 ++++---- .../Serializer/Normalizer/DateTimeNormalizer.php | 8 ++++---- .../Normalizer/DateTimeZoneNormalizer.php | 8 ++++---- .../Normalizer/DenormalizerInterface.php | 4 ++-- .../Normalizer/GetSetMethodNormalizer.php | 4 ++-- .../Normalizer/JsonSerializableNormalizer.php | 8 ++++---- .../Normalizer/NormalizableInterface.php | 2 +- .../Serializer/Normalizer/NormalizerInterface.php | 4 ++-- .../Serializer/Normalizer/ObjectNormalizer.php | 4 ++-- .../Serializer/Normalizer/PropertyNormalizer.php | 8 ++++---- .../Component/Serializer/SerializerInterface.php | 4 ++-- 31 files changed, 83 insertions(+), 86 deletions(-) diff --git a/src/Symfony/Component/Serializer/Encoder/ChainDecoder.php b/src/Symfony/Component/Serializer/Encoder/ChainDecoder.php index 2a55d93a6066..49c2680ce869 100644 --- a/src/Symfony/Component/Serializer/Encoder/ChainDecoder.php +++ b/src/Symfony/Component/Serializer/Encoder/ChainDecoder.php @@ -35,7 +35,7 @@ public function __construct(array $decoders = []) /** * {@inheritdoc} */ - final public function decode($data, $format, array $context = []) + final public function decode(string $data, string $format, array $context = []) { return $this->getDecoder($format, $context)->decode($data, $format, $context); } @@ -43,7 +43,7 @@ final public function decode($data, $format, array $context = []) /** * {@inheritdoc} */ - public function supportsDecoding($format, array $context = []): bool + public function supportsDecoding(string $format, array $context = []): bool { try { $this->getDecoder($format, $context); diff --git a/src/Symfony/Component/Serializer/Encoder/ChainEncoder.php b/src/Symfony/Component/Serializer/Encoder/ChainEncoder.php index 8bf2dfe6ef25..48722d21c1bc 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, $format, array $context = []) + final public function encode($data, string $format, array $context = []) { return $this->getEncoder($format, $context)->encode($data, $format, $context); } @@ -43,7 +43,7 @@ final public function encode($data, $format, array $context = []) /** * {@inheritdoc} */ - public function supportsEncoding($format, array $context = []): bool + public function supportsEncoding(string $format, array $context = []): bool { try { $this->getEncoder($format, $context); @@ -56,11 +56,8 @@ public function supportsEncoding($format, array $context = []): bool /** * Checks whether the normalization is needed for the given format. - * - * @param string $format - * @param array $context */ - public function needsNormalization($format, array $context = []): bool + public function needsNormalization(string $format, array $context = []): bool { $encoder = $this->getEncoder($format, $context); diff --git a/src/Symfony/Component/Serializer/Encoder/ContextAwareDecoderInterface.php b/src/Symfony/Component/Serializer/Encoder/ContextAwareDecoderInterface.php index 5ef89d5596ca..ce665f2ebc27 100644 --- a/src/Symfony/Component/Serializer/Encoder/ContextAwareDecoderInterface.php +++ b/src/Symfony/Component/Serializer/Encoder/ContextAwareDecoderInterface.php @@ -23,5 +23,5 @@ interface ContextAwareDecoderInterface extends DecoderInterface * * @param array $context options that decoders have access to */ - public function supportsDecoding($format, array $context = []); + public function supportsDecoding(string $format, array $context = []); } diff --git a/src/Symfony/Component/Serializer/Encoder/ContextAwareEncoderInterface.php b/src/Symfony/Component/Serializer/Encoder/ContextAwareEncoderInterface.php index a8893a80f91b..17789e88e9c8 100644 --- a/src/Symfony/Component/Serializer/Encoder/ContextAwareEncoderInterface.php +++ b/src/Symfony/Component/Serializer/Encoder/ContextAwareEncoderInterface.php @@ -23,5 +23,5 @@ interface ContextAwareEncoderInterface extends EncoderInterface * * @param array $context options that encoders have access to */ - public function supportsEncoding($format, array $context = []); + public function supportsEncoding(string $format, array $context = []); } diff --git a/src/Symfony/Component/Serializer/Encoder/CsvEncoder.php b/src/Symfony/Component/Serializer/Encoder/CsvEncoder.php index d575796ec765..b1a786e9bbb2 100644 --- a/src/Symfony/Component/Serializer/Encoder/CsvEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/CsvEncoder.php @@ -51,7 +51,7 @@ public function __construct(array $defaultContext = []) /** * {@inheritdoc} */ - public function encode($data, $format, array $context = []) + public function encode($data, string $format, array $context = []) { $handle = fopen('php://temp,', 'w+'); @@ -110,7 +110,7 @@ public function supportsEncoding($format) /** * {@inheritdoc} */ - public function decode($data, $format, array $context = []) + public function decode(string $data, string $format, array $context = []) { $handle = fopen('php://temp', 'r+'); fwrite($handle, $data); diff --git a/src/Symfony/Component/Serializer/Encoder/DecoderInterface.php b/src/Symfony/Component/Serializer/Encoder/DecoderInterface.php index cfc591e7adf8..10a7f3aabfb0 100644 --- a/src/Symfony/Component/Serializer/Encoder/DecoderInterface.php +++ b/src/Symfony/Component/Serializer/Encoder/DecoderInterface.php @@ -36,7 +36,7 @@ interface DecoderInterface * * @throws UnexpectedValueException */ - public function decode($data, $format, array $context = []); + public function decode(string $data, string $format, array $context = []); /** * Checks whether the deserializer can decode from given format. @@ -45,5 +45,5 @@ public function decode($data, $format, array $context = []); * * @return bool */ - public function supportsDecoding($format); + public function supportsDecoding(string $format); } diff --git a/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php b/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php index 9b9862e2acb2..3cf6b5b186c4 100644 --- a/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php +++ b/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php @@ -31,7 +31,7 @@ interface EncoderInterface * * @throws UnexpectedValueException */ - public function encode($data, $format, array $context = []); + public function encode($data, string $format, array $context = []); /** * Checks whether the serializer can encode to given format. @@ -40,5 +40,5 @@ public function encode($data, $format, array $context = []); * * @return bool */ - public function supportsEncoding($format); + public function supportsEncoding(string $format); } diff --git a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php index 7048dcf17316..cab24b41225b 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php @@ -72,7 +72,7 @@ public function __construct(array $defaultContext = []) * * @see http://php.net/json_decode json_decode */ - public function decode($data, $format, array $context = []) + public function decode(string $data, string $format, array $context = []) { $associative = $context[self::ASSOCIATIVE] ?? $this->defaultContext[self::ASSOCIATIVE]; $recursionDepth = $context[self::RECURSION_DEPTH] ?? $this->defaultContext[self::RECURSION_DEPTH]; @@ -98,7 +98,7 @@ public function decode($data, $format, array $context = []) /** * {@inheritdoc} */ - public function supportsDecoding($format) + public function supportsDecoding(string $format) { return JsonEncoder::FORMAT === $format; } diff --git a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php index 2363aead7abb..1218418c4a19 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php @@ -36,7 +36,7 @@ public function __construct(array $defaultContext = []) * * {@inheritdoc} */ - public function encode($data, $format, array $context = []) + public function encode($data, string $format, array $context = []) { $jsonEncodeOptions = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS]; $encodedJson = json_encode($data, $jsonEncodeOptions); @@ -55,7 +55,7 @@ public function encode($data, $format, array $context = []) /** * {@inheritdoc} */ - public function supportsEncoding($format) + public function supportsEncoding(string $format) { return JsonEncoder::FORMAT === $format; } diff --git a/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php b/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php index 8cb98accdf77..db2619dfe211 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, $format, array $context = []) + public function encode($data, string $format, array $context = []) { return $this->encodingImpl->encode($data, self::FORMAT, $context); } @@ -40,7 +40,7 @@ public function encode($data, $format, array $context = []) /** * {@inheritdoc} */ - public function decode($data, $format, array $context = []) + public function decode(string $data, string $format, array $context = []) { return $this->decodingImpl->decode($data, self::FORMAT, $context); } @@ -48,7 +48,7 @@ public function decode($data, $format, array $context = []) /** * {@inheritdoc} */ - public function supportsEncoding($format) + public function supportsEncoding(string $format) { return self::FORMAT === $format; } @@ -56,7 +56,7 @@ public function supportsEncoding($format) /** * {@inheritdoc} */ - public function supportsDecoding($format) + public function supportsDecoding(string $format) { return self::FORMAT === $format; } diff --git a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php index 40dccef814cc..c476ba6ec066 100644 --- a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php @@ -79,7 +79,7 @@ public function __construct(array $defaultContext = []) /** * {@inheritdoc} */ - public function encode($data, $format, array $context = []) + public function encode($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); @@ -107,7 +107,7 @@ public function encode($data, $format, array $context = []) /** * {@inheritdoc} */ - public function decode($data, $format, array $context = []) + public function decode(string $data, string $format, array $context = []) { if ('' === trim($data)) { throw new NotEncodableValueException('Invalid XML data, it can not be empty.'); @@ -176,7 +176,7 @@ public function decode($data, $format, array $context = []) /** * {@inheritdoc} */ - public function supportsEncoding($format) + public function supportsEncoding(string $format) { return self::FORMAT === $format; } @@ -184,7 +184,7 @@ public function supportsEncoding($format) /** * {@inheritdoc} */ - public function supportsDecoding($format) + public function supportsDecoding(string $format) { return self::FORMAT === $format; } diff --git a/src/Symfony/Component/Serializer/Encoder/YamlEncoder.php b/src/Symfony/Component/Serializer/Encoder/YamlEncoder.php index dc0bf7fe416d..f04955e3fba6 100644 --- a/src/Symfony/Component/Serializer/Encoder/YamlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/YamlEncoder.php @@ -43,7 +43,7 @@ public function __construct(Dumper $dumper = null, Parser $parser = null, array /** * {@inheritdoc} */ - public function encode($data, $format, array $context = []) + public function encode($data, string $format, array $context = []) { $context = array_merge($this->defaultContext, $context); @@ -53,7 +53,7 @@ public function encode($data, $format, array $context = []) /** * {@inheritdoc} */ - public function supportsEncoding($format) + public function supportsEncoding(string $format) { return self::FORMAT === $format || self::ALTERNATIVE_FORMAT === $format; } @@ -61,7 +61,7 @@ public function supportsEncoding($format) /** * {@inheritdoc} */ - public function decode($data, $format, array $context = []) + public function decode(string $data, string $format, array $context = []) { $context = array_merge($this->defaultContext, $context); @@ -71,7 +71,7 @@ public function decode($data, $format, array $context = []) /** * {@inheritdoc} */ - public function supportsDecoding($format) + public function supportsDecoding(string $format) { return self::FORMAT === $format || self::ALTERNATIVE_FORMAT === $format; } diff --git a/src/Symfony/Component/Serializer/Mapping/AttributeMetadataInterface.php b/src/Symfony/Component/Serializer/Mapping/AttributeMetadataInterface.php index bbbde922a8e9..f052d6d63498 100644 --- a/src/Symfony/Component/Serializer/Mapping/AttributeMetadataInterface.php +++ b/src/Symfony/Component/Serializer/Mapping/AttributeMetadataInterface.php @@ -34,7 +34,7 @@ public function getName(); * * @param string $group */ - public function addGroup($group); + public function addGroup(string $group); /** * Gets groups of this attribute. @@ -48,7 +48,7 @@ public function getGroups(); * * @param int|null $maxDepth */ - public function setMaxDepth($maxDepth); + public function setMaxDepth(?int $maxDepth); /** * Gets the serialization max depth for this attribute. diff --git a/src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php b/src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php index 2465f5b47e27..4060e5ac327d 100644 --- a/src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php +++ b/src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php @@ -34,7 +34,7 @@ public function __construct(array $attributes = null, bool $lowerCamelCase = tru /** * {@inheritdoc} */ - public function normalize($propertyName) + public function normalize(string $propertyName) { if (null === $this->attributes || \in_array($propertyName, $this->attributes)) { return strtolower(preg_replace('/[A-Z]/', '_\\0', lcfirst($propertyName))); @@ -46,7 +46,7 @@ public function normalize($propertyName) /** * {@inheritdoc} */ - public function denormalize($propertyName) + public function denormalize(string $propertyName) { $camelCasedName = preg_replace_callback('/(^|_|\.)+(.)/', function ($match) { return ('.' === $match[1] ? '_' : '').strtoupper($match[2]); diff --git a/src/Symfony/Component/Serializer/NameConverter/NameConverterInterface.php b/src/Symfony/Component/Serializer/NameConverter/NameConverterInterface.php index c9f66b029a9e..ce234d65762d 100644 --- a/src/Symfony/Component/Serializer/NameConverter/NameConverterInterface.php +++ b/src/Symfony/Component/Serializer/NameConverter/NameConverterInterface.php @@ -25,7 +25,7 @@ interface NameConverterInterface * * @return string */ - public function normalize($propertyName); + public function normalize(string $propertyName); /** * Converts a property name to its denormalized value. @@ -34,5 +34,5 @@ public function normalize($propertyName); * * @return string */ - public function denormalize($propertyName); + public function denormalize(string $propertyName); } diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php index fd1e6108edaa..17269afeb9f3 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php @@ -121,7 +121,7 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory /** * {@inheritdoc} */ - public function supportsNormalization($data, $format = null) + public function supportsNormalization($data, string $format = null) { return \is_object($data) && !$data instanceof \Traversable; } @@ -129,7 +129,7 @@ public function supportsNormalization($data, $format = null) /** * {@inheritdoc} */ - public function normalize($object, $format = null, array $context = []) + public function normalize($object, string $format = null, array $context = []) { if (!isset($context['cache_key'])) { $context['cache_key'] = $this->getCacheKey($format, $context); @@ -233,7 +233,7 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref * * @return string[] */ - protected function getAttributes($object, $format = null, array $context) + protected function getAttributes($object, string $format = null, array $context) { $class = $this->objectClassResolver ? ($this->objectClassResolver)($object) : \get_class($object); $key = $class.'-'.$context['cache_key']; @@ -274,7 +274,7 @@ protected function getAttributes($object, $format = null, array $context) * * @return string[] */ - abstract protected function extractAttributes($object, $format = null, array $context = []); + abstract protected function extractAttributes($object, string $format = null, array $context = []); /** * Gets the attribute value. @@ -286,12 +286,12 @@ abstract protected function extractAttributes($object, $format = null, array $co * * @return mixed */ - abstract protected function getAttributeValue($object, $attribute, $format = null, array $context = []); + abstract protected function getAttributeValue($object, string $attribute, string $format = null, array $context = []); /** * {@inheritdoc} */ - public function supportsDenormalization($data, $type, $format = null) + public function supportsDenormalization($data, $type, string $format = null) { return class_exists($type) || (interface_exists($type, false) && $this->classDiscriminatorResolver && null !== $this->classDiscriminatorResolver->getMappingForClass($type)); } @@ -299,7 +299,7 @@ public function supportsDenormalization($data, $type, $format = null) /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = null, array $context = []) + public function denormalize($data, $class, string $format = null, array $context = []) { if (!isset($context['cache_key'])) { $context['cache_key'] = $this->getCacheKey($format, $context); diff --git a/src/Symfony/Component/Serializer/Normalizer/ContextAwareDenormalizerInterface.php b/src/Symfony/Component/Serializer/Normalizer/ContextAwareDenormalizerInterface.php index 4e68dae1ee3d..c875de1b5287 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, $type, $format = null, array $context = []); + public function supportsDenormalization($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 c278b7ded9f2..ff0bb3a21d4f 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, $format = null, array $context = []); + public function supportsNormalization($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 dcf2deef806d..09914e6bc8c5 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, $format = null, array $context = []) + public function normalize($object, string $format = null, array $context = []) { return $object->normalize($this->serializer, $format, $context); } @@ -33,7 +33,7 @@ public function normalize($object, $format = null, array $context = []) /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = null, array $context = []) + public function denormalize($data, $class, string $format = null, array $context = []) { $object = $this->extractObjectToPopulate($class, $context) ?: new $class(); $object->denormalize($this->serializer, $data, $format, $context); @@ -49,7 +49,7 @@ public function denormalize($data, $class, $format = null, array $context = []) * * @return bool */ - public function supportsNormalization($data, $format = null) + public function supportsNormalization($data, string $format = null) { return $data instanceof NormalizableInterface; } @@ -63,7 +63,7 @@ public function supportsNormalization($data, $format = null) * * @return bool */ - public function supportsDenormalization($data, $type, $format = null) + public function supportsDenormalization($data, $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 0cad3f9cf984..40271331a859 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php @@ -48,7 +48,7 @@ public function __construct(MimeTypeGuesserInterface $mimeTypeGuesser = null) /** * {@inheritdoc} */ - public function normalize($object, $format = null, array $context = []) + public function normalize($object, string $format = null, array $context = []) { if (!$object instanceof \SplFileInfo) { throw new InvalidArgumentException('The object must be an instance of "\SplFileInfo".'); @@ -74,7 +74,7 @@ public function normalize($object, $format = null, array $context = []) /** * {@inheritdoc} */ - public function supportsNormalization($data, $format = null) + public function supportsNormalization($data, string $format = null) { return $data instanceof \SplFileInfo; } @@ -89,7 +89,7 @@ public function supportsNormalization($data, $format = null) * @throws InvalidArgumentException * @throws NotNormalizableValueException */ - public function denormalize($data, $class, $format = null, array $context = []) + public function denormalize($data, $class, 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.'); @@ -118,7 +118,7 @@ public function denormalize($data, $class, $format = null, array $context = []) /** * {@inheritdoc} */ - public function supportsDenormalization($data, $type, $format = null) + public function supportsDenormalization($data, $type, string $format = null) { return isset(self::$supportedTypes[$type]); } diff --git a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php index 8ed7a24f84d7..5e048103c44c 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php @@ -38,7 +38,7 @@ public function __construct(array $defaultContext = []) * * @throws InvalidArgumentException */ - public function normalize($object, $format = null, array $context = []) + public function normalize($object, string $format = null, array $context = []) { if (!$object instanceof \DateInterval) { throw new InvalidArgumentException('The object must be an instance of "\DateInterval".'); @@ -50,7 +50,7 @@ public function normalize($object, $format = null, array $context = []) /** * {@inheritdoc} */ - public function supportsNormalization($data, $format = null) + public function supportsNormalization($data, string $format = null) { return $data instanceof \DateInterval; } @@ -69,7 +69,7 @@ public function hasCacheableSupportsMethod(): bool * @throws InvalidArgumentException * @throws UnexpectedValueException */ - public function denormalize($data, $class, $format = null, array $context = []) + public function denormalize($data, $class, string $format = null, array $context = []) { if (!\is_string($data)) { throw new InvalidArgumentException(sprintf('Data expected to be a string, %s given.', \gettype($data))); @@ -96,7 +96,7 @@ public function denormalize($data, $class, $format = null, array $context = []) /** * {@inheritdoc} */ - public function supportsDenormalization($data, $type, $format = null) + public function supportsDenormalization($data, $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 8b182f72c95b..7db34c394fa9 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php @@ -46,7 +46,7 @@ public function __construct(array $defaultContext = []) * * @throws InvalidArgumentException */ - public function normalize($object, $format = null, array $context = []) + public function normalize($object, string $format = null, array $context = []) { if (!$object instanceof \DateTimeInterface) { throw new InvalidArgumentException('The object must implement the "\DateTimeInterface".'); @@ -66,7 +66,7 @@ public function normalize($object, $format = null, array $context = []) /** * {@inheritdoc} */ - public function supportsNormalization($data, $format = null) + public function supportsNormalization($data, string $format = null) { return $data instanceof \DateTimeInterface; } @@ -76,7 +76,7 @@ public function supportsNormalization($data, $format = null) * * @throws NotNormalizableValueException */ - public function denormalize($data, $class, $format = null, array $context = []) + public function denormalize($data, $class, string $format = null, array $context = []) { $dateTimeFormat = $context[self::FORMAT_KEY] ?? null; $timezone = $this->getTimezone($context); @@ -113,7 +113,7 @@ public function denormalize($data, $class, $format = null, array $context = []) /** * {@inheritdoc} */ - public function supportsDenormalization($data, $type, $format = null) + public function supportsDenormalization($data, $type, string $format = null) { return isset(self::$supportedTypes[$type]); } diff --git a/src/Symfony/Component/Serializer/Normalizer/DateTimeZoneNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateTimeZoneNormalizer.php index 8d589d71c6cc..900d436466c7 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateTimeZoneNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateTimeZoneNormalizer.php @@ -26,7 +26,7 @@ class DateTimeZoneNormalizer implements NormalizerInterface, DenormalizerInterfa * * @throws InvalidArgumentException */ - public function normalize($object, $format = null, array $context = []) + public function normalize($object, string $format = null, array $context = []) { if (!$object instanceof \DateTimeZone) { throw new InvalidArgumentException('The object must be an instance of "\DateTimeZone".'); @@ -38,7 +38,7 @@ public function normalize($object, $format = null, array $context = []) /** * {@inheritdoc} */ - public function supportsNormalization($data, $format = null) + public function supportsNormalization($data, string $format = null) { return $data instanceof \DateTimeZone; } @@ -48,7 +48,7 @@ public function supportsNormalization($data, $format = null) * * @throws NotNormalizableValueException */ - public function denormalize($data, $class, $format = null, array $context = []) + public function denormalize($data, $class, 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.'); @@ -64,7 +64,7 @@ public function denormalize($data, $class, $format = null, array $context = []) /** * {@inheritdoc} */ - public function supportsDenormalization($data, $type, $format = null) + public function supportsDenormalization($data, $type, string $format = null) { return \DateTimeZone::class === $type; } diff --git a/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php b/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php index 7a12d20f1132..41967039516e 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php @@ -44,7 +44,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, $class, $format = null, array $context = []); + public function denormalize($data, string $class, string $format = null, array $context = []); /** * Checks whether the given class is supported for denormalization by this normalizer. @@ -55,5 +55,5 @@ public function denormalize($data, $class, $format = null, array $context = []); * * @return bool */ - public function supportsDenormalization($data, $type, $format = null); + public function supportsDenormalization($data, string $type, string $format = null); } diff --git a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php index 9fcf58a5b7b2..033acadc72eb 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, $format = null) + public function supportsNormalization($data, string $format = null) { return parent::supportsNormalization($data, $format) && $this->supports(\get_class($data)); } @@ -47,7 +47,7 @@ public function supportsNormalization($data, $format = null) /** * {@inheritdoc} */ - public function supportsDenormalization($data, $type, $format = null) + public function supportsDenormalization($data, $type, string $format = null) { return parent::supportsDenormalization($data, $type, $format) && $this->supports($type); } diff --git a/src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php index 6238f5e534c7..767ac633ccf4 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, $format = null, array $context = []) + public function normalize($object, string $format = null, array $context = []) { if ($this->isCircularReference($object, $context)) { return $this->handleCircularReference($object); @@ -44,7 +44,7 @@ public function normalize($object, $format = null, array $context = []) /** * {@inheritdoc} */ - public function supportsNormalization($data, $format = null) + public function supportsNormalization($data, string $format = null) { return $data instanceof \JsonSerializable; } @@ -52,7 +52,7 @@ public function supportsNormalization($data, $format = null) /** * {@inheritdoc} */ - public function supportsDenormalization($data, $type, $format = null) + public function supportsDenormalization($data, $type, string $format = null) { return false; } @@ -60,7 +60,7 @@ public function supportsDenormalization($data, $type, $format = null) /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = null, array $context = []) + public function denormalize($data, $class, string $format = null, array $context = []) { throw new LogicException(sprintf('Cannot denormalize with "%s".', \JsonSerializable::class)); } diff --git a/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php b/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php index f7a556014363..ce4af8be5ea0 100644 --- a/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php @@ -35,5 +35,5 @@ interface NormalizableInterface * * @return array|string|int|float|bool */ - public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []); + public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = []); } diff --git a/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php b/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php index 02a211858492..cecd2c35ae2c 100644 --- a/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php @@ -38,7 +38,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, $format = null, array $context = []); + public function normalize($object, string $format = null, array $context = []); /** * Checks whether the given class is supported for normalization by this normalizer. @@ -48,5 +48,5 @@ public function normalize($object, $format = null, array $context = []); * * @return bool */ - public function supportsNormalization($data, $format = null); + public function supportsNormalization($data, string $format = null); } diff --git a/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php index 118e9856f5e9..da1be0c30792 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php @@ -60,7 +60,7 @@ public function hasCacheableSupportsMethod(): bool /** * {@inheritdoc} */ - protected function extractAttributes($object, $format = null, array $context = []) + protected function extractAttributes($object, string $format = null, array $context = []) { // If not using groups, detect manually $attributes = []; @@ -118,7 +118,7 @@ protected function extractAttributes($object, $format = null, array $context = [ /** * {@inheritdoc} */ - protected function getAttributeValue($object, $attribute, $format = null, array $context = []) + protected function getAttributeValue($object, $attribute, string $format = null, array $context = []) { $cacheKey = \get_class($object); if (!\array_key_exists($cacheKey, $this->discriminatorCache)) { diff --git a/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php index e07aec6c4e90..5991dd5b96a0 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, $format = null) + public function supportsNormalization($data, string $format = null) { return parent::supportsNormalization($data, $format) && $this->supports(\get_class($data)); } @@ -41,7 +41,7 @@ public function supportsNormalization($data, $format = null) /** * {@inheritdoc} */ - public function supportsDenormalization($data, $type, $format = null) + public function supportsDenormalization($data, $type, string $format = null) { return parent::supportsDenormalization($data, $type, $format) && $this->supports($type); } @@ -97,7 +97,7 @@ protected function isAllowedAttribute($classOrObject, $attribute, $format = null /** * {@inheritdoc} */ - protected function extractAttributes($object, $format = null, array $context = []) + protected function extractAttributes($object, string $format = null, array $context = []) { $reflectionObject = new \ReflectionObject($object); $attributes = []; @@ -118,7 +118,7 @@ protected function extractAttributes($object, $format = null, array $context = [ /** * {@inheritdoc} */ - protected function getAttributeValue($object, $attribute, $format = null, array $context = []) + protected function getAttributeValue($object, $attribute, string $format = null, array $context = []) { try { $reflectionProperty = $this->getReflectionProperty($object, $attribute); diff --git a/src/Symfony/Component/Serializer/SerializerInterface.php b/src/Symfony/Component/Serializer/SerializerInterface.php index 7a03ef943a20..2cc92e22d01f 100644 --- a/src/Symfony/Component/Serializer/SerializerInterface.php +++ b/src/Symfony/Component/Serializer/SerializerInterface.php @@ -27,7 +27,7 @@ interface SerializerInterface * * @return string */ - public function serialize($data, $format, array $context = []); + public function serialize($data, string $format, array $context = []); /** * Deserializes data into the given type. @@ -39,5 +39,5 @@ public function serialize($data, $format, array $context = []); * * @return object */ - public function deserialize($data, $type, $format, array $context = []); + public function deserialize($data, string $type, string $format, array $context = []); }