Skip to content

[Validator] Avoid TypeError and improve DX when null groups #49137

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

Open
wants to merge 2 commits into
base: 7.4
Choose a base branch
from

Conversation

alamirault
Copy link
Contributor

@alamirault alamirault commented Jan 27, 2023

Q A
Branch? 6.3
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #...
License MIT
Doc PR symfony/symfony-docs#...

Improve DX when we pass null value in array of groups

$this->validate($entity, null, ['Group 1', null])

Before this PR
TypeError: Symfony\Component\Validator\Context\ExecutionContext::isGroupValidated(): Argument #2 ($groupHash) must be of type string, null given,

@xabbuh
Copy link
Member

xabbuh commented Jan 29, 2023

There are probably more places inside the RecursiveContextualValidator where this could be done. What about doing this in normalizeGroups() instead?

@alamirault
Copy link
Contributor Author

You're right , I updated PR

@alamirault
Copy link
Contributor Author

@xabbuh Are you ok with the new version ?

}

return [$groups];
if (\in_array(null, $groups, true)) {
throw new ValidatorException('Value in array of validation groups cannot be null.');
Copy link
Member

Choose a reason for hiding this comment

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

Should be an InvalidArgumentException I suppose?
What about other types that are neither strings nor GroupSequence?
Also, since this is an improvement, it should target 6.3.

@nicolas-grekas nicolas-grekas modified the milestones: 5.4, 6.3 Apr 18, 2023
@nicolas-grekas nicolas-grekas changed the base branch from 5.4 to 6.3 April 18, 2023 08:58
@nicolas-grekas nicolas-grekas modified the milestones: 6.3, 6.4 May 23, 2023
@nicolas-grekas nicolas-grekas modified the milestones: 6.4, 7.1 Nov 15, 2023
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