Test Failed
Push — master ( f47101...348e9e )
by Ricardo
02:03
created

Cep::isSame()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Validate;
4
5
use Validate\Traits\FakeNameTrait;
6
7
class Cep implements \Validate\Contracts\Validate
8
{
9
    use FakeNameTrait;
10
11
    public static function toDatabase($cep)
12
    {
13
        return preg_replace('/[^0-9]/', '', trim($cep));
14
    }
15
    
16
    public static function toUser($cep)
17
    {
18
        return $cep;
19
    }
20
21
    public static function validate($cep)
22
    {
23
        if (preg_match('/[0-9]{2,2}([.]?)[0-9]{3,3}([- ]?)[0-9]{3}$/', self::toDatabase($cep))) {            
24
            return true;
25
        }
26
        return false;
27
    }
28
29
    public static function isSame(string $to, string $from)
30
    {
31
        return (self::toDatabase($to)===self::toDatabase($from));
32
    }
33
34
}
35