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

Validator::__call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 2
crap 2
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