ValidCreditorReferenceValidator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 18
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 16 5
1
<?php declare(strict_types=1);
2
3
namespace Sprain\SwissQrBill\Constraint;
4
5
use kmukku\phpIso11649\phpIso11649;
6
use Symfony\Component\Validator\Constraint;
7
use Symfony\Component\Validator\ConstraintValidator;
8
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
9
10
/**
11
 * @internal
12
 */
13
final class ValidCreditorReferenceValidator extends ConstraintValidator
14
{
15
    public function validate($value, Constraint $constraint): void
16
    {
17
        if (!$constraint instanceof ValidCreditorReference) {
18
            throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\ValidCreditorReference');
19
        }
20
21
        if (null === $value || '' === $value) {
22
            return;
23
        }
24
25
        $referenceGenerator = new phpIso11649();
26
27
        if (false === $referenceGenerator->validateRfReference($value)) {
28
            $this->context->buildViolation($constraint->message)
29
                ->setParameter('{{ string }}', $value)
30
                ->addViolation();
31
        }
32
    }
33
}
34