Total Complexity | 9 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class Cep implements \Validate\Contracts\Validate |
||
9 | { |
||
10 | |||
11 | public static function toDatabase($cep) |
||
12 | { |
||
13 | return preg_replace('/[^0-9]/', '', trim($cep)); |
||
14 | } |
||
15 | |||
16 | public static function toUser($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}$/', $cep) == 0 ) { |
||
24 | return false; |
||
25 | } |
||
26 | try { |
||
27 | $client = new Http(); |
||
28 | $res = $client->request('GET', 'https://viacep.com.br/ws/'.self::toDatabase($cep).'/json/'); |
||
29 | if ($res->getStatusCode() !== 200) { |
||
30 | return false; |
||
31 | } |
||
32 | $json = json_decode($res->getBody()); |
||
33 | if (isset($json->error) && $json->error = true) { |
||
34 | return false; |
||
35 | } |
||
36 | } catch (Exception $e) { |
||
37 | return false; |
||
38 | } |
||
39 | |||
40 | return true; |
||
41 | } |
||
42 | |||
43 | public static function isSame(string $to, string $from) |
||
46 | } |
||
47 | |||
48 | } |
||
49 |