8000 bug #29223 [Validator] Added the missing constraints instance checks … · symfony/symfony@b11ec05 · GitHub
[go: up one dir, main page]

Skip to content

Commit b11ec05

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
2 parents f975be2 + 0ecaead commit b11ec05

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/Symfony/Component/Validator/Constraints/BicValidator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Validator\Constraint;
1515
use Symfony\Component\Validator\ConstraintValidator;
16+
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
1617

1718
/**
1819
* @author Michael Hirschler <michael.vhirsch@gmail.com>
@@ -26,6 +27,10 @@ class BicValidator extends ConstraintValidator
2627
*/
2728
public function validate($value, Constraint $constraint)
2829
{
30+
if (!$constraint instanceof Bic) {
31+
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Bic');
32+
}
33+
2934
if (null === $value || '' === $value) {
3035< 10000 code class="diff-text syntax-highlighted-line">
return;
3136
}

src/Symfony/Component/Validator/Constraints/CountValidator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class CountValidator extends ConstraintValidator
2626
*/
2727
public function validate($value, Constraint $constraint)
2828
{
29+
if (!$constraint instanceof Count) {
30+
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Count');
31+
}
32+
2933
if (null === $value) {
3034
return;
3135
}

src/Symfony/Component/Validator/Constraints/UuidValidator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ class UuidValidator extends ConstraintValidator
8383
*/
8484
public function validate($value, Constraint $constraint)
8585
{
86-
if (null === $value || '' === $value) {
87-
return;
88-
}
89-
9086
if (!$constraint instanceof Uuid) {
9187
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Uuid');
9288
}
9389

90+
if (null === $value || '' === $value) {
91+
return;
92+
}
93+
9494
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
9595
throw new UnexpectedTypeException($value, 'string');
9696
}

0 commit comments

Comments
 (0)
You can’t perform that action at this time.
0