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 c4dcfd1

Browse filesBrowse files
committed
Fix not null return from "getCollectionValueTypes"
1 parent 4eca8d1 commit c4dcfd1
Copy full SHA for c4dcfd1

File tree

5 files changed

+15
-13
lines changed
Filter options

5 files changed

+15
-13
lines changed

‎src/Symfony/Component/PropertyInfo/Type.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Type.php
+1-10Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,7 @@ public function getCollectionValueType(): ?self
179179
{
180180
trigger_deprecation('symfony/property-info', '5.3', 'The "%s()" method is deprecated, use "getCollectionValueTypes()" instead.', __METHOD__);
181181

182-
$type = $this->getCollectionValueTypes();
183-
if (0 === \count($type)) {
184-
return null;
185-
}
186-
187-
if (\is_array($type)) {
188-
[$type] = $type;
189-
}
190-
191-
return $type;
182+
return $this->getCollectionValueTypes()[0] ?? null;
192183
}
193184

194185
/**

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,13 +473,13 @@ private function validateAndDenormalize(string $currentClass, string $attribute,
473473
if (null !== $collectionKeyType = $type->getCollectionKeyTypes()) {
474474
[$context['key_type']] = $collectionKeyType;
475475
}
476-
} elseif ($type->isCollection() && null !== ($collectionValueType = $type->getCollectionValueTypes()) && \count($collectionValueType) > 0 && Type::BUILTIN_TYPE_ARRAY === $collectionValueType[0]->getBuiltinType()) {
476+
} elseif ($type->isCollection() && \count($collectionValueType = $type->getCollectionValueTypes()) > 0 && Type::BUILTIN_TYPE_ARRAY === $collectionValueType[0]->getBuiltinType()) {
477477
// get inner type for any nested array
478478
[$innerType] = $collectionValueType;
479479

480480
// note that it will break for any other builtinType
481481
$dimensions = '[]';
482-
while (null !== $innerType->getCollectionValueTypes() && Type::BUILTIN_TYPE_ARRAY === $innerType->getBuiltinType()) {
482+
while (\count($innerType->getCollectionValueTypes()) > 0 && Type::BUILTIN_TYPE_ARRAY === $innerType->getBuiltinType()) {
483483
$dimensions .= '[]';
484484
[$innerType] = $innerType->getCollectionValueTypes();
485485
}

‎src/Symfony/Component/Validator/Mapping/Loader/PropertyInfoLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Mapping/Loader/PropertyInfoLoader.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function loadClassMetadata(ClassMetadata $metadata): bool
119119
}
120120
if (!$hasTypeConstraint) {
121121
if (1 === \count($builtinTypes)) {
122-
if ($types[0]->isCollection() && (null !== $collectionValueType = $types[0]->getCollectionValueTypes())) {
122+
if ($types[0]->isCollection() && \count($collectionValueType = $types[0]->getCollectionValueTypes()) > 0) {
123123
[$collectionValueType] = $collectionValueType;
124124
$this->handleAllConstraint($property, $allConstraint, $collectionValueType, $metadata);
125125
}

‎src/Symfony/Component/Validator/Tests/Fixtures/PropertyInfoLoaderEntity.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Fixtures/PropertyInfoLoaderEntity.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class PropertyInfoLoaderEntity
2323
public $scalar;
2424
public $object;
2525
public $collection;
26+
public $collectionOfUnknown;
2627

2728
/**
2829
* @Assert\Type(type="int")

‎src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function testLoadClassMetadata()
4444
'scalar',
4545
'object',
4646
'collection',
47+
'collectionOfUnknown',
4748
'alreadyMappedType',
4849
'alreadyMappedNotNull',
4950
'alreadyMappedNotBlank',
@@ -61,6 +62,7 @@ public function testLoadClassMetadata()
6162
[new Type(Type::BUILTIN_TYPE_STRING, true), new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_BOOL)],
6263
[new Type(Type::BUILTIN_TYPE_OBJECT, true, Entity::class)],
6364
[new Type(Type::BUILTIN_TYPE_ARRAY, true, null, true, null, new Type(Type::BUILTIN_TYPE_OBJECT, false, Entity::class))],
65+
[new Type(Type::BUILTIN_TYPE_ARRAY, true, null, true)],
6466
[new Type(Type::BUILTIN_TYPE_FLOAT, true)], // The existing constraint is float
6567
[new Type(Type::BUILTIN_TYPE_STRING, true)],
6668
[new Type(Type::BUILTIN_TYPE_STRING, true)],
@@ -81,6 +83,7 @@ public function testLoadClassMetadata()
8183
true,
8284
true,
8385
true,
86+
true,
8487
false,
8588
true
8689
))
@@ -135,6 +138,13 @@ public function testLoadClassMetadata()
135138
$this->assertInstanceOf(TypeConstraint::class, $collectionConstraints[0]->constraints[1]);
136139
$this->assertSame(Entity::class, $collectionConstraints[0]->constraints[1]->type);
137140

141+
$collectionOfUnknownMetadata = $classMetadata->getPropertyMetadata('collectionOfUnknown');
142+
$this->assertCount(1, $collectionOfUnknownMetadata);
143+
$collectionOfUnknownConstraints = $collectionOfUnknownMetadata[0]->getConstraints();
144+
$this->assertCount(1, $collectionOfUnknownConstraints);
145+
$this->assertInstanceOf(TypeConstraint::class, $collectionOfUnknownConstraints[0]);
146+
$this->assertSame('array', $collectionOfUnknownConstraints[0]->type);
147+
138148
$alreadyMappedTypeMetadata = $classMetadata->getPropertyMetadata('alreadyMappedType');
139149
$this->assertCount(1, $alreadyMappedTypeMetadata);
140150
$alreadyMappedTypeConstraints = $alreadyMappedTypeMetadata[0]->getConstraints();

0 commit comments

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