Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4db6d56

Browse filesBrowse files
[Serializer] add union types
1 parent fd0566c commit 4db6d56
Copy full SHA for 4db6d56

Some content is hidden

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

57 files changed

+143
-410
lines changed

‎src/Symfony/Component/Serializer/Annotation/Context.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Annotation/Context.php
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class Context
3535
*
3636
* @throws InvalidArgumentException
3737
*/
38-
public function __construct(array $options = [], array $context = [], array $normalizationContext = [], array $denormalizationContext = [], $groups = [])
38+
public function __construct(array $options = [], array $context = [], array $normalizationContext = [], array $denormalizationContext = [], string|array $groups = [])
3939
{
4040
if (!$context) {
4141
if (!array_intersect((array_keys($options)), ['normalizationContext', 'groups', 'context', 'value', 'denormalizationContext'])) {
@@ -48,9 +48,6 @@ public function __construct(array $options = [], array $context = [], array $nor
4848
$context = $options['value'] ?? $options['context'] ?? [];
4949
}
5050
}
51-
if (!\is_string($groups) && !\is_array($groups)) {
52-
throw new \TypeError(sprintf('"%s": Expected parameter $groups to be a string or an array of strings, got "%s".', __METHOD__, get_debug_type($groups)));
53-
}
5451

5552
$normalizationContext = $options['normalizationContext'] ?? $normalizationContext;
5653
$denormalizationContext = $options['denormalizationContext'] ?? $denormalizationContext;

‎src/Symfony/Component/Serializer/Annotation/DiscriminatorMap.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Annotation/DiscriminatorMap.php
+1-22Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,11 @@
2525
#[\Attribute(\Attribute::TARGET_CLASS)]
2626
class DiscriminatorMap
2727
{
28-
/**
29-
* @var string
30-
*/
3128
private $typeProperty;
32-
33-
/**
34-
* @var array
35-
*/
3629
private $mapping;
3730

38-
/**
39-
* @param string $typeProperty
40-
*
41-
* @throws InvalidArgumentException
42-
*/
43-
public function __construct($typeProperty, array $mapping = null)
31+
public function __construct(string $typeProperty, array $mapping)
4432
{
45-
if (\is_array($typeProperty)) {
46-
trigger_deprecation('symfony/serializer', '5.3', 'Passing an array as first argument to "%s" is deprecated. Use named arguments instead.', __METHOD__);
47-
48-
$mapping = $typeProperty['mapping'] ?? null;
49-
$typeProperty = $typeProperty['typeProperty'] ?? null;
50-
} elseif (!\is_string($typeProperty)) {
51-
throw new \TypeError(sprintf('"%s": Argument $typeProperty was expected to be a string or array, got "%s".', __METHOD__, get_debug_type($typeProperty)));
52-
}
53-
5433
if (empty($typeProperty)) {
5534
throw new InvalidArgumentException(sprintf('Parameter "typeProperty" of annotation "%s" cannot be empty.', static::class));
5635
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Annotation/Groups.php
+4-15Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,36 +32,25 @@ class Groups
3232

3333
/**
3434
* @param string|string[] $groups
35-
*
36-
* @throws InvalidArgumentException
3735
*/
38-
public function __construct($groups)
36+
public function __construct(string|array $groups)
3937
{
40-
if (\is_string($groups)) {
41-
$groups = (array) $groups;
42-
} elseif (!\is_array($groups)) {
43-
throw new \TypeError(sprintf('"%s": Parameter $groups is expected to be a string or an array of strings, got "%s".', __METHOD__, get_debug_type($groups)));
44-
} elseif (isset($groups['value'])) {
45-
trigger_deprecation('symfony/serializer', '5.3', 'Passing an array of properties as first argument to "%s" is deprecated. Use named arguments instead.', __METHOD__);
38+
$groups = (array) $groups;
4639

47-
$groups = (array) $groups['value'];
48-
}
4940
if (empty($groups)) {
5041
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" cannot be empty.', static::class));
5142
}
5243

5344
foreach ($groups as $group) {
54-
if (!\is_string($group)) {
55-
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a string or an array of strings.', static::class));
45+
if (!\is_string($group) || '' === $group) {
46+
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a string or an array of non-empty strings.', static::class));
5647
}
5748
}
5849

5950
$this->groups = $groups;
6051
}
6152

6253
/**
63-
* Gets groups.
64-
*
6554
* @return string[]
6655
*/
6756
public function getGroups()

‎src/Symfony/Component/Serializer/Annotation/MaxDepth.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Annotation/MaxDepth.php
+2-17Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,11 @@
2525
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
2626
class MaxDepth
2727
{
28-
/**
29-
* @var int
30-
*/
3128
private $maxDepth;
3229

33-
/**
34-
* @param int $maxDepth
35-
*/
36-
public function __construct($maxDepth)
30+
public function __construct(int $maxDepth)
3731
{
38-
if (\is_array($maxDepth)) {
39-
trigger_deprecation('symfony/serializer', '5.3', 'Passing an array as first argument to "%s" is deprecated. Use named arguments instead.', __METHOD__);
40-
41-
if (!isset($maxDepth['value'])) {
42-
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" should be set.', static::class));
43-
}
44-
$maxDepth = $maxDepth['value'];
45-
}
46-
47-
if (!\is_int($maxDepth) || $maxDepth <= 0) {
32+
if ($maxDepth <= 0) {
4833
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a positive integer.', static::class));
4934
}
5035

‎src/Symfony/Component/Serializer/Annotation/SerializedName.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Annotation/SerializedName.php
+2-17Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,11 @@
2525
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
2626
final class SerializedName
2727
{
28-
/**
29-
* @var string
30-
*/
3128
private $serializedName;
3229

33-
/**
34-
* @param string $serializedName
35-
*/
36-
public function __construct($serializedName)
30+
public function __construct(string $serializedName)
3731
{
38-
if (\is_array($serializedName)) {
39-
trigger_deprecation('symfony/serializer', '5.3', 'Passing an array as first argument to "%s" is deprecated. Use named arguments instead.', __METHOD__);
40-
41-
if (!isset($serializedName['value'])) {
42-
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" should be set.', static::class));
43-
}
44-
$serializedName = $serializedName['value'];
45-
}
46-
47-
if (!\is_string($serializedName) || empty($serializedName)) {
32+
if (empty($serializedName)) {
4833
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a non-empty string.', static::class));
4934
}
5035

‎src/Symfony/Component/Serializer/CacheWarmer/CompiledClassMetadataCacheWarmer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/CacheWarmer/CompiledClassMetadataCacheWarmer.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(array $classesToCompile, ClassMetadataFactoryInterfa
4040
/**
4141
* {@inheritdoc}
4242
*/
43-
public function warmUp($cacheDir)
43+
public function warmUp(string $cacheDir)
4444
{
4545
$metadatas = [];
4646

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Encoder/ChainEncoder.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(array $encoders = [])
3535
/**
3636
* {@inheritdoc}
3737
*/
38-
final public function encode($data, string $format, array $context = [])
38+
final public function encode(mixed $data, string $format, array $context = [])
3939
{
4040
return $this->getEncoder($format, $context)->encode($data, $format, $context);
4141
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Encoder/CsvEncoder.php
+1-1Lines changed: 1 addition & 1 deletion
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($data, string $format, array $context = [])
61+
public function encode(mixed $data, string $format, array $context = [])
6262
{
6363
$handle = fopen('php://temp,', 'w+');
6464

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Encoder/EncoderInterface.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface EncoderInterface
2929
*
3030
* @throws UnexpectedValueException
3131
*/
32-
public function encode($data, string $format, array $context = []);
32+
public function encode(mixed $data, string $format, array $context = []);
3333

3434
/**
3535
* Checks whether the serializer can encode to given format.

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Encoder/JsonEncode.php
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ public function __construct(array $defaultContext = [])
3232
}
3333

3434
/**
35-
* Encodes PHP data to a JSON string.
36-
*
3735
* {@inheritdoc}
3836
*/
39-
public function encode($data, string $format, array $context = [])
37+
public function encode(mixed $data, string $format, array $context = [])
4038
{
4139
$options = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS];
4240

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Encoder/JsonEncoder.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(JsonEncode $encodingImpl = null, JsonDecode $decodin
3232
/**
3333
* {@inheritdoc}
3434
*/
35-
public function encode($data, string $format, array $context = [])
35+
public function encode(mixed $data, string $format, array $context = [])
3636
{
3737
return $this->encodingImpl->encode($data, self::FORMAT, $context);
3838
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Encoder/XmlEncoder.php
+5-12Lines changed: 5 additions & 12 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($data, string $format, array $context = [])
83+
public function encode(mixed $data, string $format, array $context = [])
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);
@@ -217,10 +217,7 @@ final protected function appendCData(\DOMNode $node, string $val): bool
217217
return true;
218218
}
219219

220-
/**
221-
* @param \DOMDocumentFragment $fragment
222-
*/
223-
final protected function appendDocumentFragment(\DOMNode $node, $fragment): bool
220+
final protected function appendDocumentFragment(\DOMNode $node, \DOMDocumentFragment $fragment): bool
224221
{
225222
if ($fragment instanceof \DOMDocumentFragment) {
226223
$node->appendChild($fragment);
@@ -357,11 +354,9 @@ private function parseXmlValue(\DOMNode $node, array $context = [])
357354
/**
358355
* Parse the data and convert it to DOMElements.
359356
*
360-
* @param array|object $data
361-
*
362357
* @throws NotEncodableValueException
363358
*/
364-
private function buildXml(\DOMNode $parentNode, $data, string $xmlRootNodeName = null): bool
359+
private function buildXml(\DOMNode $parentNode, mixed $data, string $xmlRootNodeName = null): bool
365360
{
366361
$append = true;
367362
$removeEmptyTags = $this->context[self::REMOVE_EMPTY_TAGS] ?? $this->defaultContext[self::REMOVE_EMPTY_TAGS] ?? false;
@@ -431,10 +426,8 @@ private function buildXml(\DOMNode $parentNode, $data, string $xmlRootNodeName =
431426

432427
/**
433428
* Selects the type of node to create and appends it to the parent.
434-
*
435-
* @param array|object $data
436429
*/
437-
private function appendNode(\DOMNode $parentNode, $data, string $nodeName, string $key = null): bool
430+
private function appendNode(\DOMNode $parentNode, mixed $data, string $nodeName, string $key = null): bool
438431
{
439432
$node = $this->dom->createElement($nodeName);
440433
if (null !== $key) {
@@ -462,7 +455,7 @@ private function needsCdataWrapping(string $val): bool
462455
*
463456
* @throws NotEncodableValueException
464457
*/
465-
private function selectNodeType(\DOMNode $node, $val): bool
458+
private function selectNodeType(\DOMNode $node, mixed $val): bool
466459
{
467460
if (\is_array($val)) {
468461
return $this->buildXml($node, $val);

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Encoder/YamlEncoder.php
+1-1Lines changed: 1 addition & 1 deletion
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($data, string $format, array $context = [])
57+
public function encode(mixed $data, string $format, array $context = [])
5858
{
5959
$context = array_merge($this->defaultContext, $context);
6060

‎src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorFromClassMetadata.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorFromClassMetadata.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function getMappingForClass(string $class): ?ClassDiscriminatorMapping
4444
/**
4545
* {@inheritdoc}
4646
*/
47-
public function getMappingForMappedObject($object): ?ClassDiscriminatorMapping
47+
public function getMappingForMappedObject(object|string $object): ?ClassDiscriminatorMapping
4848
{
4949
if ($this->classMetadataFactory->hasMetadataFor($object)) {
5050
$metadata = $this->classMetadataFactory->getMetadataFor($object);
@@ -65,7 +65,7 @@ public function getMappingForMappedObject($object): ?ClassDiscriminatorMapping
6565
/**
6666
* {@inheritdoc}
6767
*/
68-
public function getTypeForMappedObject($object): ?string
68+
public function getTypeForMappedObject(object|string $object): ?string
6969
{
7070
if (null === $mapping = $this->getMappingForMappedObject($object)) {
7171
return null;
@@ -74,7 +74,7 @@ public function getTypeForMappedObject($object): ?string
7474
return $mapping->getMappedObjectType($object);
7575
}
7676

77-
private function resolveMappingForMappedObject($object)
77+
private function resolveMappingForMappedObject(object|string $object)
7878
{
7979
$reflectionClass = new \ReflectionClass($object);
8080
if ($parentClass = $reflectionClass->getParentClass()) {

‎src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorMapping.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorMapping.php
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ public function getClassForType(string $type): ?string
4747
return $this->typesMapping[$type] ?? null;
4848
}
4949

50-
/**
51-
* @param object|string $object
52-
*/
53-
public function getMappedObjectType($object): ?string
50+
public function getMappedObjectType(object|string $object): ?string
5451
{
5552
foreach ($this->typesMapping as $type => $typeClass) {
5653
if (is_a($object, $typeClass)) {

‎src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorResolverInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorResolverInterface.php
+2-8Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@ interface ClassDiscriminatorResolverInterface
2020
{
2121
public function getMappingForClass(string $class): ?ClassDiscriminatorMapping;
2222

23-
/**
24-
* @param object|string $object
25-
*/
26-
public function getMappingForMappedObject($object): ?ClassDiscriminatorMapping;
23+
public function getMappingForMappedObject(object|string $object): ?ClassDiscriminatorMapping;
2724

28-
/**
29-
* @param object|string $object
30-
*/
31-
public function getTypeForMappedObject($object): ?string;
25+
public function getTypeForMappedObject(object|string $object): ?string;
3226
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Mapping/Factory/CacheClassMetadataFactory.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(ClassMetadataFactoryInterface $decorated, CacheItemP
4343
/**
4444
* {@inheritdoc}
4545
*/
46-
public function getMetadataFor($value)
46+
public function getMetadataFor(string|object $value)
4747
{
4848
$class = $this->getClass($value);
4949

@@ -67,7 +67,7 @@ public function getMetadataFor($value)
6767
/**
6868
* {@inheritdoc}
6969
*/
70-
public function hasMetadataFor($value)
70+
public function hasMetadataFor(mixed $value)
7171
{
7272
return $this->decorated->hasMetadataFor($value);
7373
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactory.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(LoaderInterface $loader)
3838
/**
3939
* {@inheritdoc}
4040
*/
41-
public function getMetadataFor($value)
41+
public function getMetadataFor(string|object $value)
4242
{
4343
$class = $this->getClass($value);
4444

@@ -67,7 +67,7 @@ public function getMetadataFor($value)
6767
/**
6868
* {@inheritdoc}
6969
*/
70-
public function hasMetadataFor($value)
70+
public function hasMetadataFor(mixed $value)
7171
{
7272
return \is_object($value) || (\is_string($value) && (class_exists($value) || interface_exists($value, false)));
7373
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactoryInterface.php
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,16 @@ 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-
* @param string|object $value
38-
*
3937
* @return ClassMetadataInterface
4038
*
4139
* @throws InvalidArgumentException
4240
*/
43-
public function getMetadataFor($value);
41+
public function getMetadataFor(string|object $value);
4442

4543
/**
4644
* Checks if class has metadata.
4745
*
48-
* @param mixed $value
49-
*
5046
* @return bool
5147
*/
52-
public function hasMetadataFor($value);
48+
public function hasMetadataFor(mixed $value);
5349
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.