8000 [Serializer] add return types · symfony/symfony@9f724ca · GitHub
[go: up one dir, main page]

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

Lines changed: 1 addition & 1 deletion
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

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

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

Lines changed: 4 additions & 4 deletions
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
/** 10000
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

Lines changed: 2 additions & 6 deletions
10000
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

Lines changed: 2 additions & 6 deletions
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

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(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

Lines changed: 4 additions & 4 deletions
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
}

0 commit comments

Comments
 (0)
0