8000 [Validator] Added the missing constraints instance checks by thomasbisignani · Pull Request #29223 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Symfony/Component/Validator/Constraints/BicValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Validator/Constraints/UuidValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
0