8000 [Serializer] [5.0] Add type-hints to serializer interface · hultberg/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
}

0 commit comments

Comments
 (0)
0