Skip to content

Commit

Permalink
Updated constraints and code to be symfony5 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDC committed Oct 27, 2023
1 parent c196839 commit bba1223
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
}
],
"require": {
"symfony/validator": "^4",
"symfony/security-core": "^4"
"symfony/validator": "^4|^5",
"symfony/security-core": "^4|^5"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 6 additions & 6 deletions src/Constraints/PasswordValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PasswordValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Password) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Password');
throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\Password');
}

if ($value instanceof UserInterface) {
Expand All @@ -32,9 +32,9 @@ public function validate($value, Constraint $constraint)
throw new MissingOptionsException('The plainPasswordAccessor and plainPasswordProperty options are required when using the class constraint.', ['plainPasswordAccessor', 'plainPasswordProperty']);
}

$stringValue = (string) $value->$plainPasswordAccessor();
$stringValue = (string)$value->$plainPasswordAccessor();
} else {
$stringValue = (string) $value;
$stringValue = (string)$value;
}

$length = mb_strlen($stringValue);
Expand All @@ -45,7 +45,7 @@ public function validate($value, Constraint $constraint)
$constraint->min === $constraint->max ? $constraint->exactMessage : $constraint->maxMessage,
['{{ value }}' => $this->formatValue($stringValue), '{{ limit }}' => $constraint->max]
)
->setPlural((int) $constraint->max)
->setPlural((int)$constraint->max)
->setCode(Password::TOO_LONG_ERROR)
->addViolation();
}
Expand All @@ -55,7 +55,7 @@ public function validate($value, Constraint $constraint)
$constraint->min === $constraint->max ? $constraint->exactMessage : $constraint->minMessage,
['{{ value }}' => $this->formatValue($stringValue), '{{ limit }}' => $constraint->min]
)
->setPlural((int) $constraint->min)
->setPlural((int)$constraint->min)
->setCode(Password::TOO_SHORT_ERROR)
->addViolation();
}
Expand Down Expand Up @@ -91,7 +91,7 @@ private function buildViolation($value, string $message, array $parameters = [])
$violation = $this->context->buildViolation($message);
$violation->setInvalidValue($value);
foreach ($parameters as $parameterKey => $parameter) {
$violation->setParameter($parameterKey, $parameter);
$violation->setParameter($parameterKey, (string)$parameter);
}

if ($isClassConstraint) {
Expand Down

0 comments on commit bba1223

Please sign in to comment.