Completed
Push — master ( 963eb0...3c7090 )
by Tyler
03:14
created

Validator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 22
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 4 2
A isPhone() 0 4 1
A isE164() 0 9 1
1
<?php
2
3
namespace Tylercd100\Validator\Phone;
4
5
class Validator
6
{
7 12
    public function __call($a, $b)
8
    {
9 12
        return empty($b[0]) || $this->{$a}($b[0]);
10
    }
11
12 3
    protected function isPhone($value)
13
    {
14 3
        return $this->isE164($value);
15
    }
16
17 9
    protected function isE164($value)
18
    {
19 9
        $conditions = [];
20 9
        $conditions[] = strpos($value, "+") === 0;
21 9
        $conditions[] = strlen($value) >= 9;
22 9
        $conditions[] = strlen($value) <= 16;
23 9
        $conditions[] = preg_match("/[^\d+]/i", $value) === 0;
24 9
        return (bool) array_product($conditions);
25
    }
26
}
27