8000 [Serializer] [5.0] Add type-hints to serializer interface · symfony/symfony@68b588c · GitHub
[go: up one dir, main page]

Skip to content

Commit 68b588c

Browse files
committed
[Serializer] [5.0] Add type-hints to serializer interface
1 parent cf8cfeb commit 68b588c

31 files changed

+83
-86
lines changed

src/Symfony/Component/Serializer/Encoder/ChainDecoder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public function __construct(array $decoders = [])
3535
/**
3636
* {@inheritdoc}
3737
*/
38-
final public function decode($data, $format, array $context = [])
38+
final public function decode(string $data, string $format, array $context = [])
3939
{
4040
return $this->getDecoder($format, $context)->decode($data, $format, $context);
4141
}
4242

4343
/**
4444
* {@inheritdoc}
4545
*/
46-
public function supportsDecoding($format, array $context = []): bool
46+
public function supportsDecoding(string $format, array $context = []): bool
4747
{
4848
try {
4949
$this->getDecoder($format, $context);

src/Symfony/Component/Serializer/Encoder/ChainEncoder.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public function __construct(array $encoders = [])
3535
/**
3636
* {@inheritdoc}
3737
*/
38-
final public function encode($data, $format, array $context = [])
38+
final public function encode($data, string $format, array $context = [])
3939
{
4040
return $this->getEncoder($format, $context)->encode($data, $format, $context);
4141
}
4242

4343
/**
4444
* {@inheritdoc}
4545
*/
46-
public function supportsEncoding($format, array $context = []): bool
46+
public function supportsEncoding(string $format, array $context = []): bool
4747
{
4848
try {
4949
$this->getEncoder($format, $context);
@@ -56,11 +56,8 @@ public function supportsEncoding($format, array $context = []): bool
5656

5757
/**
5858
* Checks whether the normalization is needed for the given format.
59-
*
60-
* @param string $format
61-
* @param array $context
6259
*/
63-
public function needsNormalization($format, array $context = []): bool
60+
public function needsNormalization(string $format, array $context = []): bool
6461
{
6562
$encoder = $this->getEncoder($format, $context);
6663

src/Symfony/Component/Serializer/Encoder/ContextAwareDecoderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ interface ContextAwareDecoderInterface extends DecoderInterface
2323
*
2424
* @param array $context options that decoders have access to
2525
*/
26-
public function supportsDecoding($format, array $context = []);
26+
public function supportsDecoding(string $format, array $context = []);
2727
}

src/Symfony/Component/Serializer/Encoder/ContextAwareEncoderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ interface ContextAwareEncoderInterface extends EncoderInterface
2323
*
2424
* @param array $context options that encoders have access to
2525
*/
26-
public function supportsEncoding($format, array $context = []);
26+
public function supportsEncoding(string $format, array $context = []);
2727
}

src/Symfony/Component/Serializer/Encoder/CsvEncoder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct(array $defaultContext = [])
5151
/**
5252
* {@inheritdoc}
5353
*/
54-
public function encode($data, $format, array $context = [])
54+
public function encode($data, string $format, array $context = [])
5555
{
5656
$handle = fopen('php://temp,', 'w+');
5757

@@ -110,7 +110,7 @@ public function supportsEncoding($format)
110110
/**
111111
* {@inheritdoc}
112112
*/
113-
public function decode($data, $format, array $context = [])
113+
public function decode(string $data, string $format, array $context = [])
114114
{
115115
$handle = fopen('php://temp', 'r+');
116116
fwrite($handle, $data);

src/Symfony/Component/Serializer/Encoder/DecoderInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ interface DecoderInterface
3636
*
3737
* @throws UnexpectedValueException
3838
*/
39-
public function decode($data, $format, array $context = []);
39+
public function decode(string $data, string $format, array $context = []);
4040

4141
/**
4242
* Checks whether the deserializer can decode from given format.
@@ -45,5 +45,5 @@ public function decode($data, $format, array $context = []);
4545
*
4646
* @return bool
4747
*/
48-
public function supportsDecoding($format);
48+
public function supportsDecoding(string $format);
4949
}

src/Symfony/Component/Serializer/Encoder/EncoderInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface EncoderInterface
3131
*
3232
* @throws UnexpectedValueException
3333
*/
34-
public function encode($data, $format, array $context = []);
34+
public function encode($data, string $format, array $context = []);
3535

3636
/**
3737
* Checks whether the serializer can encode to given format.
@@ -40,5 +40,5 @@ public function encode($data, $format, array $context = []);
4040
*
4141
* @return bool
4242
*/
43-
public function supportsEncoding($format);
43+
public function supportsEncoding(string $format);
4444
}

src/Symfony/Component/Serializer/Encoder/JsonDecode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function __construct(array $defaultContext = [])
7272
*
7373
* @see http://php.net/json_decode json_decode
7474
*/
75-
public function decode($data, $format, array $context = [])
75+
public function decode(string $data, string $format, array $context = [])
7676
{
7777
$associative = $context[self::ASSOCIATIVE] ?? $this->defaultContext[self::ASSOCIATIVE];
7878
$recursionDepth = $context[self::RECURSION_DEPTH] ?? $this->defaultContext[self::RECURSION_DEPTH];
@@ -98,7 +98,7 @@ public function decode($data, $format, array $context = [])
9898
/**
9999
* {@inheritdoc}
100100
*/
101-
public function supportsDecoding($format)
101+
public function supportsDecoding(string $format)
102102
{
103103
return JsonEncoder::FORMAT === $format;
104104
}

src/Symfony/Component/Serializer/Encoder/JsonEncode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(array $defaultContext = [])
3636
*
3737
* {@inheritdoc}
3838
*/
39-
public function encode($data, $format, array $context = [])
39+
public function encode($data, string $format, array $context = [])
4040
{
4141
$jsonEncodeOptions = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS];
4242
$encodedJson = json_encode($data, $jsonEncodeOptions);
@@ -55,7 +55,7 @@ public function encode($data, $format, array $context = [])
5555
/**
5656
* {@inheritdoc}
5757
*/
58-
public function supportsEncoding($format)
58+
public function supportsEncoding(string $format)
5959
{
6060
return JsonEncoder::FORMAT === $format;
6161
}

src/Symfony/Component/Serializer/Encoder/JsonEncoder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,31 @@ public function __construct(JsonEncode $encodingImpl = null, JsonDecode $decodin
3232
/**
3333
* {@inheritdoc}
3434
*/
35-
public function encode($data, $format, array $context = [])
35+
public function encode($data, string $format, array $context = [])
3636
{
3737
return $this->encodingImpl->encode($data, self::FORMAT, $context);
3838
}
3939

4040
/**
4141
* {@inheritdoc}
4242
*/
43-
public function decode($data, $format, array $context = [])
43+
public function decode(string $data, string $format, array $context = [])
4444
{
4545
return $this->decodingImpl->decode($data, self::FORMAT, $context);
4646
}
4747

4848
/**
4949
* {@inheritdoc}
5050
*/
51-
public function supportsEncoding($format)
51+
public function supportsEncoding(string $format)
5252
{
5353
return self::FORMAT === $format;
5454
}
5555

5656
/**
5757
* {@inheritdoc}
5858
*/
59-
public function supportsDecoding($format)
59+
public function supportsDecoding(string $format)
6060
{
6161
return self::FORMAT === $format;
6262
}

src/Symfony/Component/Serializer/Encoder/XmlEncoder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function __construct(array $defaultContext = [])
7979
/**
8080
* {@inheritdoc}
8181
*/
82-
public function encode($data, $format, array $context = [])
82+
public function encode($data, string $format, array $context = [])
8383
{
8484
$encoderIgnoredNodeTypes = $context[self::ENCODER_IGNORED_NODE_TYPES] ?? $this->defaultContext[self::ENCODER_IGNORED_NODE_TYPES];
8585
$ignorePiNode = \in_array(XML_PI_NODE, $encoderIgnoredNodeTypes, true);
@@ -107,7 +107,7 @@ public function encode($data, $format, array $context = [])
107107
/**
108108
* {@inheritdoc}
109109
*/
110-
public function decode($data, $format, array $context = [])
110+
public function decode(string $data, string $format, array $context = [])
111111
{
112112
if ('' === trim($data)) {
113113
throw new NotEncodableValueException('Invalid XML data, it can not be empty.');
@@ -176,15 +176,15 @@ public function decode($data, $format, array $context = [])
176176
/**
177177
* {@inheritdoc}
178178
*/
179-
public function supportsEncoding($format)
179+
public function supportsEncoding(string $format)
180180
{
181181
return self::FORMAT === $format;
182182
}
183183

184184
/**
185185
* {@inheritdoc}
186186
*/
187-
public function supportsDecoding($format)
187+
public function supportsDecoding(string $format)
188188
{
189189
return self::FORMAT === $format;
190190
}

src/Symfony/Component/Serializer/Encoder/YamlEncoder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(Dumper $dumper = null, Parser $parser = null, array
4343
/**
4444
* {@inheritdoc}
4545
*/
46-
public function encode($data, $format, array $context = [])
46+
public function encode($data, string $format, array $context = [])
4747
{
4848
$context = array_merge($this->defaultContext, $context);
4949

@@ -53,15 +53,15 @@ public function encode($data, $format, array $context = [])
5353
/**
5454
* {@inheritdoc}
5555
*/
56-
public function supportsEncoding($format)
56+
public function supportsEncoding(string $format)
5757
{
5858
return self::FORMAT === $format || self::ALTERNATIVE_FORMAT === $format;
5959
}
6060

6161
/**
6262
* {@inheritdoc}
6363
*/
64-
public function decode($data, $format, array $context = [])
64+
public function decode(string $data, string $format, array $context = [])
6565
{
6666
$context = array_merge($this->defaultContext, $context);
6767

@@ -71,7 +71,7 @@ public function decode($data, $format, array $context = [])
7171
/**
7272
* {@inheritdoc}
7373
*/
74-
public function supportsDecoding($format)
74+
public function supportsDecoding(string $format)
7575
{
7676
return self::FORMAT === $format || self::ALTERNATIVE_FORMAT === $format;
7777
}

src/Symfony/Component/Serializer/Mapping/AttributeMetadataInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function getName();
3434
*
3535
* @param string $group
3636
*/
37-
public function addGroup($group);
37+
public function addGroup(string $group);
3838

3939
/**
4040
* Gets groups of this attribute.
@@ -48,7 +48,7 @@ public function getGroups();
4848
*
4949
* @param int|null $maxDepth
5050
*/
51-
public function setMaxDepth($maxDepth);
51+
public function setMaxDepth(?int $maxDepth);
5252

5353
/**
5454
* Gets the serialization max depth for this attribute.

src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(array $attributes = null, bool $lowerCamelCase = tru
3434
/**
3535
* {@inheritdoc}
3636
*/
37-
public function normalize($propertyName)
37+
public function normalize(string $propertyName)
3838
{
3939
if (null === $this->attributes || \in_array($propertyName, $this->attributes)) {
4040
return strtolower(preg_replace('/[A-Z]/', '_\\0', lcfirst($propertyName)));
@@ -46,7 +46,7 @@ public function normalize($propertyName)
4646
/**
4747
* {@inheritdoc}
4848
*/
49-
public function denormalize($propertyName)
49+
public function denormalize(string $propertyName)
5050
{
5151
$camelCasedName = preg_replace_callback('/(^|_|\.)+(.)/', function ($match) {
5252
return ('.' === $match[1] ? '_' : '').strtoupper($match[2]);

src/Symfony/Component/Serializer/NameConverter/NameConverterInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface NameConverterInterface
2525
*
2626
* @return string
2727
*/
28-
public function normalize($propertyName);
28+
public function normalize(string $propertyName);
2929

3030
/**
3131
* Converts a property name to its denormalized value.
@@ -34,5 +34,5 @@ public function normalize($propertyName);
3434
*
3535
* @return string
3636
*/
37-
public function denormalize($propertyName);
37+
public function denormalize(string $propertyName);
3838
}

src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory
121121
/**
122122
* {@inheritdoc}
123123
*/
124-
public function supportsNormalization($data, $format = null)
124+
public function supportsNormalization($data, string $format = null)
125125
{
126126
return \is_object($data) && !$data instanceof \Traversable;
127127
}
128128

129129
/**
130130
* {@inheritdoc}
131131
*/
132-
public function normalize($object, $format = null, array $context = [])
132+
public function normalize($object, string $format = null, array $context = [])
133133
{
134134
if (!isset($context['cache_key'])) {
135135
$context['cache_key'] = $this->getCacheKey($format, $context);
@@ -233,7 +233,7 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
233233
*
234234
* @return string[]
235235
*/
236-
protected function getAttributes($object, $format = null, array $context)
236+
protected function getAttributes($object, string $format = null, array $context)
237237
{
238238
$class = $this->objectClassResolver ? ($this->objectClassResolver)($object) : \get_class($object);
239239
$key = $class.'-'.$context['cache_key'];
@@ -274,7 +274,7 @@ protected function getAttributes($object, $format = null, array $context)
274274
*
275275
* @return string[]
276276
*/
277-
abstract protected function extractAttributes($object, $format = null, array $context = []);
277+
abstract protected function extractAttributes($object, string $format = null, array $context = []);
278278

279279
/**
280280
* Gets the attribute value.
@@ -286,20 +286,20 @@ abstract protected function extractAttributes($object, $format = null, array $co
286286
*
287287
* @return mixed
288288
*/
289-
abstract protected function getAttributeValue($object, $attribute, $format = null, array $context = []);
289+
abstract protected function getAttributeValue($object, string $attribute, string $format = null, array $context = []);
290290

291291
/**
292292
* {@inheritdoc}
293293
*/
294-
public function supportsDenormalization($data, $type, $format = null)
294+
public function supportsDenormalization($data, $type, string $format = null)
295295
{
296296
return class_exists($type) || (interface_exists($type, false) && $this->classDiscriminatorResolver && null !== $this->classDiscriminatorResolver->getMappingForClass($type));
297297
}
298298

299299
/**
300300
* {@inheritdoc}
301301
*/
302-
public function denormalize($data, $class, $format = null, array $context = [])
302+
public function denormalize($data, $class, string $format = null, array $context = [])
303303
{
304304
if (!isset($context['cache_key'])) {
305305
$context['cache_key'] = $this->getCacheKey($format, $context);

src/Symfony/Component/Serializer/Normalizer/ContextAwareDenormalizerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ interface ContextAwareDenormalizerInterface extends DenormalizerInterface
2323
*
2424
* @param array $context options that denormalizers have access to
2525
*/
26-
public function supportsDenormalization($data, $type, $format = null, array $context = []);
26+
public function supportsDenormalization($data, string $type, string $format = null, array $context = []);
2727
}

src/Symfony/Component/Serializer/Normalizer/ContextAwareNormalizerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ interface ContextAwareNormalizerInterface extends NormalizerInterface
2323
*
2424
* @param array $context options that normalizers have access to
2525
*/
26-
public function supportsNormalization($data, $format = null, array $context = []);
26+
public function supportsNormalization($data, string $format = null, array $context = []);
2727
}

0 commit comments

Comments
 (0)
0