| Conditions | 8 |
| Paths | 8 |
| Total Lines | 27 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 8.013 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 17 | 15 | public function validate($value, Constraint $constraint) |
|
| 18 | { |
||
| 19 | 15 | if (!$constraint instanceof Closure) { |
|
| 20 | throw new UnexpectedTypeException($constraint, Closure::class); |
||
| 21 | } |
||
| 22 | |||
| 23 | 15 | $error = ($constraint->callback)($value, $this->context->getRoot(), $this->context); |
|
| 24 | 15 | $code = null; |
|
| 25 | |||
| 26 | 15 | if ($error === true) { |
|
| 27 | 1 | return; |
|
| 28 | } |
||
| 29 | |||
| 30 | 15 | if ($error === false) { |
|
| 31 | 1 | $error = $constraint->message; |
|
| 32 | } |
||
| 33 | |||
| 34 | 15 | if ($error) { |
|
| 35 | 15 | if (is_array($error)) { |
|
| 36 | 3 | $code = $error['code'] ?? null; |
|
| 37 | 3 | $error = $error['message'] ?? null; |
|
| 38 | } |
||
| 39 | |||
| 40 | 15 | $this->context->buildViolation($error ?: $constraint->message) |
|
| 41 | 15 | ->setParameter('{{ value }}', $this->formatValue($value)) |
|
| 42 | 15 | ->setCode($code ?: 'CUSTOM_ERROR') |
|
| 43 | 15 | ->addViolation() |
|
| 44 | ; |
||
| 48 |