Skip to content

Qualification of "collection" constraints is confusing #11167

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

Closed
stof opened this issue Mar 15, 2019 · 3 comments
Closed

Qualification of "collection" constraints is confusing #11167

stof opened this issue Mar 15, 2019 · 3 comments

Comments

@stof
Copy link
Member

stof commented Mar 15, 2019

https://symfony.com/doc/current/reference/constraints.html groups constraints into categories. But the collection constraints category looks confusing to me. I don't understand what "collection" means in this title:

  • Locale, Language and Country validate the value as belonging to a given set of values
  • Choice does a similar job, but additionally supports being used on an array when using its multiple option (which is not exactly equivalent to using @All(@Choice(multiple=false)), as it reports only the first invalid value when using multiple=true and does not support Traversable)
  • Count applies on an array or Countable value (so the "collection" concept here might be the validated value)
  • UniqueEntity is a class-level constraint validating uniqueness in the DB. I don't see any concept of collection here
  • Collection is about applying constraints on specific keys of an array, for cases where you use it as a struct (what Hack calls a shape), and precisely not when treating the array as a collection

And All is about applying the same constraints on all items of an iterable (useful to validate collections of items) and is not part of that category.

@stof
Copy link
Member Author

stof commented Mar 15, 2019

Btw, it might make sense to rename the Collection constraint to something less confusing

@xabbuh
Copy link
Member

xabbuh commented Mar 15, 2019

We should probably regroup them a bit. For example, we could add a Choice category that only contains Choice, Locale, Language and Country.

@stof
Copy link
Member Author

stof commented Mar 15, 2019

btw, UserPassword should probably be moved to the String Constraints category, as it validates a string as being the current user password

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants