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

[Form] fix some type annotations #42012

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
Jul 19, 2021

Conversation

nicolas-grekas
Copy link
Member

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

Backported from #41998

The change in FormValidator is likely a bug fix, but it could be an incomplete one.
testFieldsValidateInSequenceWithNestedGroupsArray triggers a call to getConstraintsInGroups with an array.

I'd appreciate if @HeahDude, @xabbuh, or anyone with a better knowledge of Form could have a look please.

src/Symfony/Component/Form/Button.php Show resolved Hide resolved
src/Symfony/Component/Form/SubmitButton.php Show resolved Hide resolved
@@ -56,7 +56,7 @@ class GroupSequence
/**
* The groups in the sequence.
*
* @var string[]|string[][]|GroupSequence[]
* @var array<string|string[]|GroupSequence>
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually have tests that confirm that nested group sequences did ever fully work?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't, because constraints are empty on the only test case that does so... But a deep TypeError looks like something is like something is missing. Maybe just a check with a clear error message. The doc mentions nested groups btw.

Copy link
Member

Choose a reason for hiding this comment

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

Nested groups should be okay. The GroupSequence part looks suspicious to me. What error would we get when changing the annotation to array<string|string[]>|GroupSequence?

Copy link
Member Author

Choose a reason for hiding this comment

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

RecursiveContextualValidator has many instanceof GroupSequence checks that map to this possibility. But FormValidator doesn't handle it at all.

@nicolas-grekas
Copy link
Member Author

@nicolas-grekas
Copy link
Member Author

See rationale at #42013 (comment)

*
* @return ChoiceListView The choice list view
* @return ChoiceListView
*/
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

I mean using mixed for a decorator makes sense as the class does not know what it decorates that might have widened the range of accepted parameters types.
But in theory this applies to all arguments. So in theory you would also need to remove the type from ChoiceListInterface $list and accept mixed there. This might go to far. But it's a thought expirement.

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 might go to far. But it's a thought experiment.

I agree with this :)

@nicolas-grekas nicolas-grekas merged commit d64f7cd into symfony:4.4 Jul 19, 2021
@@ -260,8 +260,16 @@ private static function resolveValidationGroups($groups, FormInterface $form)

private static function getConstraintsInGroups($constraints, $group)
{
return array_filter($constraints, static function (Constraint $constraint) use ($group) {
return \in_array($group, $constraint->groups, true);
$groups = (array) $group;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is coming from \Symfony\Component\Validator\Constraints\GroupSequence::$groups and according to it's type, $group itself could also be a GroupSequence again. So there is still something not right.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's true, yet nobody reported this as a bug ever, so that the urgency on this is zero on my side :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Using a nested array seems to be the same as using a nested GroupSequence. If the nested group sequence is not supported, we probably should just remove the type from GroupSequence::$groups. It's also not documented in https://symfony.com/doc/current/validation/sequence_provider.html

@nicolas-grekas nicolas-grekas deleted the form-phpdoc branch July 19, 2021 11:50
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.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.