-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[OptionsResolver] Fix an error message to be more accurate #30442
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
4f822e5
to
8cd409d
Compare
There are a lot of changes unrelated to the PR' goal, which will make revision and approval difficult, I suggest you revert them and create a separate PR or issue to discuss about that? By the way, CS fixes and code refactoring should be done in highest branch (master) and lower branchs for bugfix only, that's why code version 4.2+ has improvements that 3.4 doesn't have. |
Why do not discuss it here? |
Yes, please revert all the changes that are not necessary for the bugfix. This just makes reviewing the changes harder than needed. |
8cd409d
to
26fc322
Compare
Done |
3b6a98e
to
4b22c46
Compare
src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php
Outdated
Show resolved
Hide resolved
ce249ba
to
16286c7
Compare
16286c7
to
308ed6e
Compare
The changes look rather complicated to me. If I am not mistaken, most of the complexity comes from composing the error message for nested arrays. I played with this a bit myself and came up with something simpler: https://github.com/symfony/symfony/compare/3.4...xabbuh:issue-30432?expand=1 Though tests don't pass with these changes yet. Would you like to give it a try? |
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.
The changes look rather complicated to me. If I am not mistaken, most of the complexity comes from composing the error message for nested arrays. I played with this a bit myself and came up with something simpler: symfony/symfony/compare/3.4...xabbuh:issue-30432?expand=1 Though tests don't pass with these changes yet. Would you like to give it a try?
Thanks! I looked at this and tried to add some test cases.
For instance [[123], ['string[]', 'string']
throws message 'The option "option" with value array is expected to be of type "string[]" or "string", but is of type "integer".'
I think we should get rid of verifyArrayType
method at all (it looks weird to me and seems also too complicated).
Ping me in slack if you want to discuss it a bit more.
src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php
Outdated
Show resolved
Hide resolved
308ed6e
to
fd67b95
Compare
Thanks @xabbuh Following changes in the above link, I've refactored PR's code. Seems like it contains much fewer changes and certainly easier to review now. |
b2721b3
to
dad7b4d
Compare
$fmtAllowedTypes = implode('" or "', $allowedTypes); | ||
$fmtProvidedTypes = implode('|', array_keys($invalidTypes)); | ||
|
||
$allowedContainsArrayType = \count(array_filter( |
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.
Is this logic needed? Wouldn't something like $allowedContainsArrayType = '[]' === substr($type, -2);
be enough?
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.
Actually, it's not enough, see test testResolveFailsIfInvalidType
and data set in 575
and 576
lines.
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.
@xabbuh ping
dad7b4d
to
dc4383d
Compare
dc4383d
to
d1fb955
Compare
@dimabory Sorry for the long delay. Could you please rebase here? |
fc4ace3
to
6addfa5
Compare
done... |
6addfa5
to
7fa2fc2
Compare
Thank you @dimabory. |
…te (dimabory) This PR was merged into the 3.4 branch. Discussion ---------- [OptionsResolver] Fix an error message to be more accurate | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #30432 | License | MIT | Doc PR | See #30432 for more details: > **Symfony version(s) affected**: 3.4, maybe other versions too (not tested) > > **Description** > Error message when allowedTypes is an array contains `[]` but should not: > `The option "testme" with value array is expected to be of type "string[]", but one of the elements is of type "integer[]".` > It should be: > `The option "testme" with value array is expected to be of type "string[]", but one of the elements is of type "integer".` > > **How to reproduce** > > ``` > $resolver = (new OptionsResolver()) > ->setDefault('testme', []) > ->setAllowedTypes('testme', ['string[]']) > ->resolve(['testme' => ['test', 12]]); > ``` In addition I changed an error message to be more accurate if provided more than one incorrect value: > [...] is expected to be of type "integer[][]", but is of type "integer|boolean|string". Commits ------- 7fa2fc2 #30432 fix an error message
I did not manage to resolve the conflicts when merging 3.4 into 4.3 so this is not part of the branch. |
Done in #34157 |
…te (yceruto) This PR was merged into the 4.3 branch. Discussion ---------- [OptionsResolver] Fix an error message to be more accurate | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #30432 | License | MIT | Doc PR | - Follow-up #30442 for 4.3 Commits ------- 1be68a7 Fix an error message to be more accurate
See #30432 for more details:
In addition I changed an error message to be more
accurate if provided more than one incorrect value: