Completed
Push — master ( 9061cf...d4ded0 )
by Sullivan
08:23 queued 05:46
created

PhoneNumberValidator::validate()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.2
cc 4
eloc 6
nc 2
nop 2
1
<?php
2
3
namespace SLLH\IsoCodesValidator\Constraints;
4
5
use IsoCodes;
6
use SLLH\IsoCodesValidator\AbstractIsoCodesConstraintValidator;
7
use Symfony\Component\Validator\Constraint;
8
9
/**
10
 * @author Sullivan Senechal <[email protected]>
11
 */
12
class PhoneNumberValidator extends AbstractIsoCodesConstraintValidator
13
{
14
    /**
15
     * @param mixed                  $value
16
     * @param PhoneNumber|Constraint $constraint
17
     */
18
    public function validate($value, Constraint $constraint)
19
    {
20
        parent::validate($value, $constraint);
21
22
        if ($value && !IsoCodes\PhoneNumber::validate(
23
                $value,
24
                PhoneNumber::ANY === $constraint->country ? null : $constraint->country
25
            )) {
26
            $this->createViolation($constraint->message);
27
        }
28
    }
29
}
30