Skip to content

Commit 24ed379

Browse files
committed
minor #46776 [Validator] refactoring IsTrueValidator (sfmok)
This PR was merged into the 6.2 branch. Discussion ---------- [Validator] refactoring IsTrueValidator | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no | Deprecations? | no | License | MIT | Refactoring? | yes Commits ------- ad4f6f677e refactoring IsTrueValidator
2 parents 736d051 + 7fb2843 commit 24ed379

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

Constraints/IsTrueValidator.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@ public function validate(mixed $value, Constraint $constraint)
2929
throw new UnexpectedTypeException($constraint, IsTrue::class);
3030
}
3131

32-
if (null === $value) {
32+
if (null === $value || true === $value || 1 === $value || '1' === $value) {
3333
return;
3434
}
3535

36-
if (true !== $value && 1 !== $value && '1' !== $value) {
37-
$this->context->buildViolation($constraint->message)
38-
->setParameter('{{ value }}', $this->formatValue($value))
39-
->setCode(IsTrue::NOT_TRUE_ERROR)
40-
->addViolation();
41-
}
36+
$this->context->buildViolation($constraint->message)
37+
->setParameter('{{ value }}', $this->formatValue($value))
38+
->setCode(IsTrue::NOT_TRUE_ERROR)
39+
->addViolation();
4240
}
4341
}

0 commit comments

Comments
 (0)