Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/validator/Constraints/CountValidator.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
23 /** | 23 /** |
24 * {@inheritdoc} | 24 * {@inheritdoc} |
25 */ | 25 */ |
26 public function validate($value, Constraint $constraint) | 26 public function validate($value, Constraint $constraint) |
27 { | 27 { |
28 if (!$constraint instanceof Count) { | |
29 throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Count'); | |
30 } | |
31 | |
28 if (null === $value) { | 32 if (null === $value) { |
29 return; | 33 return; |
30 } | 34 } |
31 | 35 |
32 if (!is_array($value) && !$value instanceof \Countable) { | 36 if (!\is_array($value) && !$value instanceof \Countable) { |
33 throw new UnexpectedTypeException($value, 'array or \Countable'); | 37 throw new UnexpectedTypeException($value, 'array or \Countable'); |
34 } | 38 } |
35 | 39 |
36 $count = count($value); | 40 $count = \count($value); |
37 | 41 |
38 if (null !== $constraint->max && $count > $constraint->max) { | 42 if (null !== $constraint->max && $count > $constraint->max) { |
39 $this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage) | 43 $this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage) |
40 ->setParameter('{{ count }}', $count) | 44 ->setParameter('{{ count }}', $count) |
41 ->setParameter('{{ limit }}', $constraint->max) | 45 ->setParameter('{{ limit }}', $constraint->max) |