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

ValidCreditorReferenceValidator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 14
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 12 4
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
}