Skip to content

[Serializer][Validator] Fix not null return from "getCollectionValueTypes" #41463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2021

Conversation

jderusse
Copy link
Member

Q A
Branch? 5.3
Bug fix? yes
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

Currently experimenting An exception has been thrown during the rendering of a template ("Notice: Undefined offset: 0").

When a property is an array and PropertyInfo is not able to guess the type of CollectionValue

@jderusse jderusse force-pushed the fix-propertyinfo-array branch from c428704 to c4dcfd1 Compare May 31, 2021 12:40
@jderusse jderusse added this to the 5.3 milestone May 31, 2021
@carsonbot carsonbot changed the title Fix not null return from "getCollectionValueTypes" [Serializer][Validator] Fix not null return from "getCollectionValueTypes" May 31, 2021
@@ -473,13 +473,13 @@ private function validateAndDenormalize(string $currentClass, string $attribute,
if (null !== $collectionKeyType = $type->getCollectionKeyTypes()) {
[$context['key_type']] = $collectionKeyType;
}
} elseif ($type->isCollection() && null !== ($collectionValueType = $type->getCollectionValueTypes()) && \count($collectionValueType) > 0 && Type::BUILTIN_TYPE_ARRAY === $collectionValueType[0]->getBuiltinType()) {
} elseif ($type->isCollection() && \count($collectionValueType = $type->getCollectionValueTypes()) > 0 && Type::BUILTIN_TYPE_ARRAY === $collectionValueType[0]->getBuiltinType()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the argument of count() can never be null? (same below)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method has been introduced in symfony/property-info: 5.3 and the method is typehinted to return an array.

public function getCollectionValueTypes(): array

@fabpot
Copy link
Member

fabpot commented Jun 2, 2021

Thank you @jderusse.

@fabpot fabpot merged commit f8e021a into symfony:5.3 Jun 2, 2021
@fabpot fabpot mentioned this pull request Jun 2, 2021
hultberg pushed a commit to hultberg/symfony that referenced this pull request Sep 17, 2021
…etCollectionValueTypes" (jderusse)

This PR was merged into the 5.3 branch.

Discussion
----------

[Serializer][Validator] Fix not null return from "getCollectionValueTypes"

| Q             | A
| ------------- | ---
| Branch?       | 5.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Currently experimenting `An exception has been thrown during the rendering of a template ("Notice: Undefined offset: 0").`

When a property is an array and PropertyInfo is not able to guess the type of CollectionValue

Commits
-------

c4dcfd1 Fix not null return from "getCollectionValueTypes"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants