Skip to content

Commit 9f724ca

Browse files
[Serializer] add return types
1 parent cce4ed3 commit 9f724ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+133
-203
lines changed

src/Symfony/Component/Serializer/Annotation/Groups.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct(string|array $groups)
5151
/**
5252
* @return string[]
5353
*/
54-
public function getGroups()
54+
public function getGroups(): array
5555
{
5656
return $this->groups;
5757
}

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

+1-1
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(string $format, array $context = []);
26+
public function supportsDecoding(string $format, array $context = []): bool;
2727
}

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

+1-1
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(string $format, array $context = []);
26+
public function supportsEncoding(string $format, array $context = []): bool;
2727
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function __construct(array $defaultContext = [])
5858
/**
5959
* {@inheritdoc}
6060
*/
61-
public function encode(mixed $data, string $format, array $context = [])
61+
public function encode(mixed $data, string $format, array $context = []): string
6262
{
6363
$handle = fopen('php://temp,', 'w+');
6464

@@ -123,15 +123,15 @@ public function encode(mixed $data, string $format, array $context = [])
123123
/**
124124
* {@inheritdoc}
125125
*/
126-
public function supportsEncoding(string $format)
126+
public function supportsEncoding(string $format): bool
127127
{
128128
return self::FORMAT === $format;
129129
}
130130

131131
/**
132132
* {@inheritdoc}
133133
*/
134-
public function decode(string $data, string $format, array $context = [])
134+
public function decode(string $data, string $format, array $context = []): mixed
135135
{
136136
$handle = fopen('php://temp', 'r+');
137137
fwrite($handle, $data);
@@ -209,7 +209,7 @@ public function decode(string $data, string $format, array $context = [])
209209
/**
210210
* {@inheritdoc}
211211
*/
212-
public function supportsDecoding(string $format)
212+
public function supportsDecoding(string $format): bool
213213
{
214214
return self::FORMAT === $format;
215215
}

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,14 @@ interface DecoderInterface
3030
* are encouraged to document which formats they support in a non-inherited
3131
* phpdoc comment.
3232
*
33-
* @return mixed
34-
*
3533
* @throws UnexpectedValueException
3634
*/
37-
public function decode(string $data, string $format, array $context = []);
35+
public function decode(string $data, string $format, array $context = []): mixed;
3836

3937
/**
4038
* Checks whether the deserializer can decode from given format.
4139
*
4240
* @param string $format Format name
43-
*
44-
* @return bool
4541
*/
46-
public function supportsDecoding(string $format);
42+
public function supportsDecoding(string $format): bool;
4743
}

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,14 @@ interface EncoderInterface
2525
* @param string $format Format name
2626
* @param array $context Options that normalizers/encoders have access to
2727
*
28-
* @return string
29-
*
3028
* @throws UnexpectedValueException
3129
*/
32-
public function encode(mixed $data, string $format, array $context = []);
30+
public function encode(mixed $data, string $format, array $context = []): string;
3331

3432
/**
3533
* Checks whether the serializer can encode to given format.
3634
*
3735
* @param string $format Format name
38-
*
39-
* @return bool
4036
*/
41-
public function supportsEncoding(string $format);
37+
public function supportsEncoding(string $format): bool;
4238
}

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,11 @@ public function __construct(array $defaultContext = [])
6666
* json_decode_options: integer
6767
* Specifies additional options as per documentation for json_decode
6868
*
69-
* @return mixed
70-
*
7169
* @throws NotEncodableValueException
7270
*
7371
* @see https://php.net/json_decode
7472
*/
75-
public function decode(string $data, string $format, array $context = [])
73+
public function decode(string $data, string $format, array $context = []): mixed
7674
{
7775
$associative = $context[self::ASSOCIATIVE] ?? $this->defaultContext[self::ASSOCIATIVE];
7876
$recursionDepth = $context[self::RECURSION_DEPTH] ?? $this->defaultContext[self::RECURSION_DEPTH];
@@ -98,7 +96,7 @@ public function decode(string $data, string $format, array $context = [])
9896
/**
9997
* {@inheritdoc}
10098
*/
101-
public function supportsDecoding(string $format)
99+
public function supportsDecoding(string $format): bool
102100
{
103101
return JsonEncoder::FORMAT === $format;
104102
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(array $defaultContext = [])
3434
/**
3535
* {@inheritdoc}
3636
*/
37-
public function encode(mixed $data, string $format, array $context = [])
37+
public function encode(mixed $data, string $format, array $context = []): string
3838
{
3939
$options = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS];
4040

@@ -58,7 +58,7 @@ public function encode(mixed $data, string $format, array $context = [])
5858
/**
5959
* {@inheritdoc}
6060
*/
61-
public function supportsEncoding(string $format)
61+
public function supportsEncoding(string $format): bool
6262
{
6363
return JsonEncoder::FORMAT === $format;
6464
}

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

+4-4
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(mixed $data, string $format, array $context = [])
35+
public function encode(mixed $data, string $format, array $context = []): string
3636
{
3737
return $this->encodingImpl->encode($data, self::FORMAT, $context);
3838
}
3939

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

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

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

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function __construct(array $defaultContext = [])
8080
/**
8181
* {@inheritdoc}
8282
*/
83-
public function encode(mixed $data, string $format, array $context = [])
83+
public function encode(mixed $data, string $format, array $context = []): string
8484
{
8585
$encoderIgnoredNodeTypes = $context[self::ENCODER_IGNORED_NODE_TYPES] ?? $this->defaultContext[self::ENCODER_IGNORED_NODE_TYPES];
8686
$ignorePiNode = \in_array(\XML_PI_NODE, $encoderIgnoredNodeTypes, true);
@@ -108,7 +108,7 @@ public function encode(mixed $data, string $format, array $context = [])
108108
/**
109109
* {@inheritdoc}
110110
*/
111-
public function decode(string $data, string $format, array $context = [])
111+
public function decode(string $data, string $format, array $context = []): mixed
112112
{
113113
if ('' === trim($data)) {
114114
throw new NotEncodableValueException('Invalid XML data, it can not be empty.');
@@ -175,15 +175,15 @@ public function decode(string $data, string $format, array $context = [])
175175
/**
176176
* {@inheritdoc}
177177
*/
178-
public function supportsEncoding(string $format)
178+
public function supportsEncoding(string $format): bool
179179
{
180180
return self::FORMAT === $format;
181181
}
182182

183183
/**
184184
* {@inheritdoc}
185185
*/
186-
public function supportsDecoding(string $format)
186+
public function supportsDecoding(string $format): bool
187187
{
188188
return self::FORMAT === $format;
189189
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function __construct(Dumper $dumper = null, Parser $parser = null, array
5454
/**
5555
* {@inheritdoc}
5656
*/
57-
public function encode(mixed $data, string $format, array $context = [])
57+
public function encode(mixed $data, string $format, array $context = []): string
5858
{
5959
$context = array_merge($this->defaultContext, $context);
6060

@@ -68,15 +68,15 @@ public function encode(mixed $data, string $format, array $context = [])
6868
/**
6969
* {@inheritdoc}
7070
*/
71-
public function supportsEncoding(string $format)
71+
public function supportsEncoding(string $format): bool
7272
{
7373
return self::FORMAT === $format || self::ALTERNATIVE_FORMAT === $format;
7474
}
7575

7676
/**
7777
* {@inheritdoc}
7878
*/
79-
public function decode(string $data, string $format, array $context = [])
79+
public function decode(string $data, string $format, array $context = []): mixed
8080
{
8181
$context = array_merge($this->defaultContext, $context);
8282

@@ -86,7 +86,7 @@ public function decode(string $data, string $format, array $context = [])
8686
/**
8787
* {@inheritdoc}
8888
*/
89-
public function supportsDecoding(string $format)
89+
public function supportsDecoding(string $format): bool
9090
{
9191
return self::FORMAT === $format || self::ALTERNATIVE_FORMAT === $format;
9292
}

src/Symfony/Component/Serializer/Exception/ExtraAttributesException.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ public function __construct(array $extraAttributes, \Throwable $previous = null)
3131

3232
/**
3333
* Get the extra attributes that are not allowed.
34-
*
35-
* @return array
3634
*/
37-
public function getExtraAttributes()
35+
public function getExtraAttributes(): array
3836
{
3937
return $this->extraAttributes;
4038
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function setMaxDepth(?int $maxDepth)
119119
/**
120120
* {@inheritdoc}
121121
*/
122-
public function getMaxDepth()
122+
public function getMaxDepth(): ?int
123123
{
124124
return $this->maxDepth;
125125
}
@@ -261,7 +261,7 @@ public function merge(AttributeMetadataInterface $attributeMetadata)
261261
*
262262
* @return string[]
263263
*/
264-
public function __sleep()
264+
public function __sleep(): array
265265
{
266266
return ['name', 'groups', 'maxDepth', 'serializedName', 'ignore', 'normalizationContexts', 'denormalizationContexts'];
267267
}

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ public function setMaxDepth(?int $maxDepth);
4646

4747
/**
4848
* Gets the serialization max depth for this attribute.
49-
*
50-
* @return int|null
5149
*/
52-
public function getMaxDepth();
50+
public function getMaxDepth(): ?int;
5351

5452
/**
5553
* Sets the serialization name for this attribute.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function setClassDiscriminatorMapping(ClassDiscriminatorMapping $mapping
128128
*
129129
* @return string[]
130130
*/
131-
public function __sleep()
131+
public function __sleep(): array
132132
{
133133
return [
134134
'name',

src/Symfony/Component/Serializer/Mapping/Factory/CacheClassMetadataFactory.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Serializer\Mapping\Factory;
1313

1414
use Psr\Cache\CacheItemPoolInterface;
15+
use Symfony\Component\Serializer\Mapping\ClassMetadataInterface;
1516

1617
/**
1718
* Caches metadata using a PSR-6 implementation.
@@ -43,7 +44,7 @@ public function __construct(ClassMetadataFactoryInterface $decorated, CacheItemP
4344
/**
4445
* {@inheritdoc}
4546
*/
46-
public function getMetadataFor(string|object $value)
47+
public function getMetadataFor(string|object $value): ClassMetadataInterface
4748
{
4849
$class = $this->getClass($value);
4950

@@ -67,7 +68,7 @@ public function getMetadataFor(string|object $value)
6768
/**
6869
* {@inheritdoc}
6970
*/
70-
public function hasMetadataFor(mixed $value)
71+
public function hasMetadataFor(mixed $value): bool
7172
{
7273
return $this->decorated->hasMetadataFor($value);
7374
}

src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactory.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Serializer\Mapping\Factory;
1313

1414
use Symfony\Component\Serializer\Mapping\ClassMetadata;
15+
use Symfony\Component\Serializer\Mapping\ClassMetadataInterface;
1516
use Symfony\Component\Serializer\Mapping\Loader\LoaderInterface;
1617

1718
/**
@@ -38,7 +39,7 @@ public function __construct(LoaderInterface $loader)
3839
/**
3940
* {@inheritdoc}
4041
*/
41-
public function getMetadataFor(string|object $value)
42+
public function getMetadataFor(string|object $value): ClassMetadataInterface
4243
{
4344
$class = $this->getClass($value);
4445

@@ -67,7 +68,7 @@ public function getMetadataFor(string|object $value)
6768
/**
6869
* {@inheritdoc}
6970
*/
70-
public function hasMetadataFor(mixed $value)
71+
public function hasMetadataFor(mixed $value): bool
7172
{
7273
return \is_object($value) || (\is_string($value) && (class_exists($value) || interface_exists($value, false)));
7374
}

src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactoryInterface.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,12 @@ interface ClassMetadataFactoryInterface
3434
* {@link \Symfony\Component\Serializer\Mapping\Loader\LoaderInterface::loadClassMetadata()} method for further
3535
* configuration. At last, the new object is returned.
3636
*
37-
* @return ClassMetadataInterface
38-
*
3937
* @throws InvalidArgumentException
4038
*/
41-
public function getMetadataFor(string|object $value);
39+
public function getMetadataFor(string|object $value): ClassMetadataInterface;
4240

4341
/**
4442
* Checks if class has metadata.
45-
*
46-
* @return bool
4743
*/
48-
public function hasMetadataFor(mixed $value);
44+
public function hasMetadataFor(mixed $value): bool;
4945
}

src/Symfony/Component/Serializer/Mapping/Loader/AnnotationLoader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct(Reader $reader = null)
5151
/**
5252
* {@inheritdoc}
5353
*/
54-
public function loadClassMetadata(ClassMetadataInterface $classMetadata)
54+
public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
5555
{
5656
$reflectionClass = $classMetadata->getReflectionClass();
5757
$className = $reflectionClass->name;

src/Symfony/Component/Serializer/Mapping/Loader/LoaderChain.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct(array $loaders)
5050
/**
5151
* {@inheritdoc}
5252
*/
53-
public function loadClassMetadata(ClassMetadataInterface $metadata)
53+
public function loadClassMetadata(ClassMetadataInterface $metadata): bool
5454
{
5555
$success = false;
5656

@@ -64,7 +64,7 @@ public function loadClassMetadata(ClassMetadataInterface $metadata)
6464
/**
6565
* @return LoaderInterface[]
6666
*/
67-
public function getLoaders()
67+
public function getLoaders(): array
6868
{
6969
return $this->loaders;
7070
}

0 commit comments

Comments
 (0)