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

PhoneNumberValidator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 18
rs 10

1 Method

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