Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Validator] Add hasViolations method to ConstraintViolationList #23493

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

ostrolucky
Copy link
Contributor

@ostrolucky ostrolucky commented Jul 12, 2017

Q A
Branch? 3.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #11939
License MIT
Doc PR -

This improves DX and performance for most common use case of the validator

@ostrolucky ostrolucky force-pushed the ConstraintViolationList_hasViolations branch from 1085848 to e68c4e8 Compare July 22, 2017 20:30
@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Jul 25, 2017
@nicolas-grekas
Copy link
Member

Calling the count() method will have the same result, isn't it?

@ostrolucky
Copy link
Contributor Author

count():

  • obfuscates intent a lot.
  • no autocomplete
  • needlessly "iterates" over all constraints instead of just checking if it has at least one constraint

Please see referenced issue, I didn't make up this DX issue

@nicolas-grekas
Copy link
Member

no autocomplete

why? it's a method, so works with autocomplete, isn't it?

needlessly "iterates" over all constraints

where? the code does just a count($this->violations), did I miss something?

I didn't make up this DX issue

I'm sure you didn't. We just know how each new public methods adds up to the maintenance burden, so we challenge changes, that's just normal.

@ostrolucky
Copy link
Contributor Author

why? it's a method, so works with autocomplete, isn't it?

Yes it does via calling ->count(), but official way (according docs) is to use count($errors). That's also what could be improved - there is currently no "correct" way to do this. I will do the PR for docs if this will be merged. Also even when you call ->count(), autocomplete won't autocomplete > 0 for you and without it, it won't pass coding guideliness in top teams since if ($errors->count()) is even less explicit than if ($errors->count() > 0)

where? the code does just a count($this->violations), did I miss something?

Ok I thought PHP needs to do that internally to get the count, turns out I was wrong, but count($array) is still 2x slower than (bool)$array.

we challenge changes, that's just normal.

Gotcha, I just wish ideas were challenged inside an issue first. I didn't see any complaints there

This is similar PR which seems to have big support #23471

@jvasseur
Copy link
Contributor

jvasseur commented Jul 28, 2017

#23471 is quite different: it increase performances by stopping the search for files as soon as one of them is found where here the performance improvement are only a few less instructions.

@ostrolucky
Copy link
Contributor Author

Both are mainly DX improvements. To make code easier to type and make intent clearer.

@nicolas-grekas
Copy link
Member

@symfony/deciders we need to make a decision here. Personally I'm "-0" :)

@ogizanagi
Copy link
Contributor

ogizanagi commented Sep 26, 2017

Same. I don't really see a benefit and it'll not be part of the ConstraintViolationListInterface interface. So it's quite limited.

@xabbuh
Copy link
Member

xabbuh commented Sep 26, 2017

same for me

@ostrolucky
Copy link
Contributor Author

I see. Thanks for consideration. Close the related issue as well please.

@ostrolucky ostrolucky closed this Sep 26, 2017
@ostrolucky ostrolucky deleted the ConstraintViolationList_hasViolations branch November 4, 2017 01:28
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.

6 participants