-
Notifications
You must be signed in to change notification settings - Fork 354
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
Strict Enum/Const Object Checking #518
Conversation
@erayd @martin-helmich please review |
Needs a code style fix, but otherwise looks good 👍. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to comply with code style rules.
@erayd I took care of the linting, but I don't know what's going on with the |
@@ -53,7 +53,7 @@ public function addError(ConstraintError $constraint, JsonPointer $path = null, | |||
'pointer' => ltrim(strval($path ?: new JsonPointer('')), '#'), | |||
'message' => ucfirst(vsprintf($message, array_map(function ($val) { | |||
if (is_scalar($val)) { | |||
return $val; | |||
return var_export($val, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra credit: I noticed that the const error string was producing this message for bool type:
Does not have a value equal to 1
instead of
Does not have a value equal to true
So what do we do with this? |
@shmax I don't think the hhvm build is related, but it needs fixing. I'm happy for that to be in a different PR. However, the failing tests on all builds introduced in your latest commit do need fixing. |
Oh, heh, didn't realize the other tests had broken. Thanks much. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - thanks 👍
No prob. Anything else you want me to take a look at? |
Fix for #517
@erayd correctly deduced that the non-strict object comparisons happening in
EnumConstraint
andConstConstraint
were opening type comparison holes on their member values. For example, the following test would pass:PHP rules governing object type equality checking are somewhat infamous. From the docs:
It provides no mechanism for doing strict member-by-member comparisons, so for this PR I drew in a library dedicated to this kind of thing, Parity.