Completed
Push — master ( 31cc79...dd89a0 )
by Manuel
05:17
created

ValidCreditorReferenceValidator::validate()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 3
nop 2
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
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
9
class ValidCreditorReferenceValidator extends ConstraintValidator
10
{
11
    public function validate($value, Constraint $constraint)
12
    {
13
        if (null === $value || '' === $value) {
14
            return;
15
        }
16
17
        $referenceGenerator = new phpIso11649();
18
19
        if (false === $referenceGenerator->validateRfReference($value)) {
20
            $this->context->buildViolation($constraint->message)
21
                ->setParameter('{{ string }}', $value)
22
                ->addViolation();
23
        }
24
    }
25
}