comparison vendor/symfony/validator/Constraints/BicValidator.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
11 11
12 namespace Symfony\Component\Validator\Constraints; 12 namespace Symfony\Component\Validator\Constraints;
13 13
14 use Symfony\Component\Validator\Constraint; 14 use Symfony\Component\Validator\Constraint;
15 use Symfony\Component\Validator\ConstraintValidator; 15 use Symfony\Component\Validator\ConstraintValidator;
16 use Symfony\Component\Validator\Exception\UnexpectedTypeException;
16 17
17 /** 18 /**
18 * @author Michael Hirschler <michael.vhirsch@gmail.com> 19 * @author Michael Hirschler <michael.vhirsch@gmail.com>
19 * 20 *
20 * @see https://en.wikipedia.org/wiki/ISO_9362#Structure 21 * @see https://en.wikipedia.org/wiki/ISO_9362#Structure
24 /** 25 /**
25 * {@inheritdoc} 26 * {@inheritdoc}
26 */ 27 */
27 public function validate($value, Constraint $constraint) 28 public function validate($value, Constraint $constraint)
28 { 29 {
30 if (!$constraint instanceof Bic) {
31 throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Bic');
32 }
33
29 if (null === $value || '' === $value) { 34 if (null === $value || '' === $value) {
30 return; 35 return;
31 } 36 }
32 37
33 $canonicalize = str_replace(' ', '', $value); 38 $canonicalize = str_replace(' ', '', $value);
34 39
35 // the bic must be either 8 or 11 characters long 40 // the bic must be either 8 or 11 characters long
36 if (!in_array(strlen($canonicalize), array(8, 11))) { 41 if (!\in_array(\strlen($canonicalize), [8, 11])) {
37 $this->context->buildViolation($constraint->message) 42 $this->context->buildViolation($constraint->message)
38 ->setParameter('{{ value }}', $this->formatValue($value)) 43 ->setParameter('{{ value }}', $this->formatValue($value))
39 ->setCode(Bic::INVALID_LENGTH_ERROR) 44 ->setCode(Bic::INVALID_LENGTH_ERROR)
40 ->addViolation(); 45 ->addViolation();
41 46