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

[Validator] Allow multiple atPath() on ConstraintViolationBuilder #36553

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
wants to merge 5 commits into from

Conversation

ABGEO
Copy link
Contributor

@ABGEO ABGEO commented Apr 23, 2020

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

Allow multiple atPath() in ConstraintViolationBuilder to add multiple ConstraintViolations at the same time.

@nicolas-grekas nicolas-grekas added this to the next milestone Apr 23, 2020
@nicolas-grekas nicolas-grekas changed the title ✨ #36544 Allow multiple atPath() on ConstraintViolationBuilder. [Validator] Allow multiple atPath() on ConstraintViolationBuilder. Apr 23, 2020
@nicolas-grekas nicolas-grekas changed the title [Validator] Allow multiple atPath() on ConstraintViolationBuilder. [Validator] Allow multiple atPath() on ConstraintViolationBuilder Apr 23, 2020
@nicolas-grekas
Copy link
Member

nicolas-grekas commented Apr 23, 2020

Don't miss adding some tests please.

@ABGEO
Copy link
Contributor Author

ABGEO commented Apr 25, 2020

@nicolas-grekas I found out that my changes are breaking tests. First of all, I'll fix them, and then provide new tests for this feature.

@ABGEO
Copy link
Contributor Author

ABGEO commented Apr 25, 2020

I have added some tests for this feature, so I think this PR is ready to review.

@xabbuh
Copy link
Member

xabbuh commented Apr 26, 2020

I am afraid that making this change would be a BC break as it would completely change the current behaviour. To make this more clear I have started to write some tests for the class which should illustrate the current behaviour (see #36584) which to depend on can totally make sense from my point of view.

@ABGEO
Copy link
Contributor Author

ABGEO commented Apr 26, 2020

@xabbuh when you call atPath() twice, the second call adds the path to the result of the first (The first call: data.foo, The second - data.foo.bar). I think this is the wrong behavior. In my case, the paths are stored in array:

['data.foo', 'data.bar']

and the addViolation() adds validation to the foo and bar fields.

If we don’t need this behavior, there is another way. Create a new method - andPath(string $path). in this case, atPath() will work the way it works, and andPath() will add another path.

@xabbuh
Copy link
Member

xabbuh commented Apr 27, 2020

when you call atPath() twice, the second call adds the path to the result of the first (The first call: data.foo, The second - data.foo.bar). I think this is the wrong behavior.

Well, at least that's the documented behaviour (and we thus cannot change it without breaking BC):

The passed path will be appended to the current property path of the execution context.

This sentence is part of the docblock of ConstraintViolationBuilderInterface::atPath():

If we don’t need this behavior, there is another way. Create a new method - andPath(string $path). in this case, atPath() will work the way it works, and andPath() will add another path.

What I would then find confusing is that calling addViolation() would not only add one violation (as I would expect from this name), but several ones. Maybe another solution could be to make it easy to reuse a constraint violation builder for another constraint.

@xabbuh
Copy link
Member

xabbuh commented Apr 27, 2020

Rereading the linked issue I think a rather simple solution would be to use clone before calling atPath().

@fabpot
Copy link
Member

fabpot commented Aug 12, 2020

@ABGEO Are you interested in trying @xabbuh suggestion?

@ABGEO
Copy link
Contributor Author

ABGEO commented Aug 12, 2020

@fabpot there is nothing to do there. I think we can close this PR and related issue.

@fabpot fabpot closed this Aug 12, 2020
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.2 Oct 5, 2020
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.

[Validation] Allow multiple atPath()s at callback constraint
6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.