-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Throw NotNormalizableException instead of InvalidArgumentException in ArrayDenormalizer #46652
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
Conversation
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
c94f365
to
d65a686
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Btw, to me, it's a feature, therefore it should target the 6.2 branch 🙂
d65a686
to
a9ca866
Compare
Done, the target branch is now 6.2. |
a9ca866
to
7ee6dca
Compare
You're welcome! Don't forget to update the changelog as well |
…tException in ArrayDenormalizer
7ee6dca
to
d549f55
Compare
I also noted that. But I don't know if it's a BC or not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me
@lyrixx Same, I was not sure. But after some thinking, I think it is a BC because it will break try/catch blocks based on InvalidArgumentException. |
It replaces a logic exception (which are not meant to be caught, meant to be fixed in code) with a runtime exception, so no BC break to me. |
if (!str_ends_with($type, '[]')) { | ||
throw new InvalidArgumentException('Unsupported class: '.$type); | ||
} | ||
|
||
if (!\is_array($data)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why inverting the order with the check on the type? Calling is_array()
is cheaper than calling str_ends_with()
, so it should be done first (especially because this method is ok the hot path and can be called hundreds of times).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NorthBlue333 Can you answer this question please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, IHMO, there is no need to change the order of checks there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, sorry did not have much time for those PRs. I will take a look during the end of the week.
if (!str_ends_with($type, '[]')) { | ||
throw new InvalidArgumentException('Unsupported class: '.$type); | ||
} | ||
|
||
if (!\is_array($data)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NorthBlue333 Can you answer this question please?
While wanting to rebase with |
Thanks @NorthBlue333 |
As stated in #46649, I think the ArrayDenormalizer should throw a NotNormalizableValueException in case of not-array $data.
I have also added NotNormalizableValueException to DenormalizerInterface's
denormalize
method PHPDoc.