Permalink
Browse files

bug #29223 [Validator] Added the missing constraints instance checks …

…(thomasbisignani)

This PR was merged into the 2.8 branch.

Discussion
----------

[Validator] Added the missing constraints instance checks

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

This PR adds the constraints instance checks missing to limit the validators use.

This behavior is already implemented in all built-in validators, but it was missed in two validators.

Commits
-------

0ecaead [Validator] Added the missing constraints instance checks
  • Loading branch information...
nicolas-grekas committed Nov 15, 2018
2 parents f975be2 + 0ecaead commit b11ec05282ca098d585bc01e7f1e67723746456a
@@ -13,6 +13,7 @@
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
/**
* @author Michael Hirschler <michael.vhirsch@gmail.com>
@@ -26,6 +27,10 @@ class BicValidator extends ConstraintValidator
*/
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Bic) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Bic');
}
if (null === $value || '' === $value) {
return;
}
@@ -26,6 +26,10 @@ class CountValidator extends ConstraintValidator
*/
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Count) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Count');
}
if (null === $value) {
return;
}
@@ -83,14 +83,14 @@ class UuidValidator extends ConstraintValidator
*/
public function validate($value, Constraint $constraint)
{
if (null === $value || '' === $value) {
return;
}
if (!$constraint instanceof Uuid) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Uuid');
}
if (null === $value || '' === $value) {
return;
}
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}

0 comments on commit b11ec05

Please sign in to comment.