Skip to content

Commit a5f7ad6

Browse files
committed
[Validator] Checked the constraint class in constraint validators
1 parent dcdf890 commit a5f7ad6

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Validator/Constraints/UserPasswordValidator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Validator\Constraint;
1818
use Symfony\Component\Validator\ConstraintValidator;
1919
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
20+
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
2021

2122
class UserPasswordValidator extends ConstraintValidator
2223
{
@@ -34,6 +35,10 @@ public function __construct(SecurityContextInterface $securityContext, EncoderFa
3435
*/
3536
public function validate($password, Constraint $constraint)
3637
{
38+
if (!$constraint instanceof UserPassword) {
39+
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\UserPassword');
40+
}
41+
3742
$user = $this->securityContext->getToken()->getUser();
3843

3944
if (!$user instanceof UserInterface) {

0 commit comments

Comments
 (0)