Conditions | 6 |
Paths | 8 |
Total Lines | 20 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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 | } |
||
49 |