8000 [Validator] Simplify `NoSuspiciousCharactersValidator` · symfony/symfony@816e1fc · GitHub
[go: up one dir, main page]

Skip to content

Commit 816e1fc

Browse files
committed
[Validator] Simplify NoSuspiciousCharactersValidator
1 parent 27760c5 commit 816e1fc

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

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

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Symfony\Component\Validator\Exception\UnexpectedValueException;
1919

2020
/**
21-
* @author Mathieu Lechat <mathieu.lechat@les-tilleuls.coop>
21+
* @author Mathieu Lechat <math.lechat@gmail.com>
2222
*/
2323
class NoSuspiciousCharactersValidator extends ConstraintValidator
2424
{
@@ -94,24 +94,12 @@ public function validate(mixed $value, Constraint $constraint): void
9494

9595
$checker->setChecks($checks);
9696

97-
if (!$checker->isSuspicious($value)) {
98-
return;
99-
}
100-
101-
foreach (self::CHECK_ERROR as $check => $error) {
102-
if (!($checks & $check)) {
103-
continue;
104-
}
105-
106-
$checker->setChecks($check);
107-
108-
if (!$checker->isSuspicious($value)) {
109-
continue;
110-
}
97+
if ($checker->isSuspicious($value, $error)) {
98+
['messageProperty' => $messageProperty, 'code' => $code] = self::CHECK_ERROR[$error];
11199

112-
$this->context->buildViolation($constraint->{$error['messageProperty']})
100+
$this->context->buildViolation($constraint->$messageProperty)
113101
->setParameter('{{ value }}', $this->formatValue($value))
114-
->setCode($error['code'])
102+
->setCode($code)
115103
->addViolation()
116104
;
117105
}

0 commit comments

Comments
 (0)
0