Test Failed
Push — master ( 0272e0...b7ca35 )
by Adriano
04:06 queued 26s
created

ApiCEP::normalizeResponse()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 19
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 16
nc 2
nop 1
dl 0
loc 19
rs 9.7333
c 1
b 0
f 0
1
<?php
2
3
namespace Wead\ZipCode\WS;
4
5
use Wead\ZipCode\Contracts\ProviderContract;
6
7
class ApiCEP extends ProviderContract
8
{
9
    public function getAddressFromZipcode($zipCode)
10
    {
11
        $zipCode = preg_replace('/[^0-9]/im', '', $zipCode);
12
13
        $endPoint = "https://ws.apicep.com/cep/{$zipCode}.json";
14
15
        $content = file_get_contents($endPoint);
16
17
        $response = json_decode($content);
18
19
        return $this->normalizeResponse((array)$response);
20
    }
21
22
    private function normalizeResponse($address)
23
    {
24
        if (sizeof($address) > 0 && strlen($address['address']) > 0) {
25
            return [
26
                "status" => true,
27
                "address" => $address["address"],
28
                "district" => $address["district"],
29
                "city" => $address["city"],
30
                "state" => $address["state"],
31
                "api" => "ApiCEP"
32
            ];
33
        } else {
34
            return [
35
                "status" => false,
36
                "address" => null,
37
                "district" => null,
38
                "city" => null,
39
                "state" => null,
40
                "api" => "ApiCEP"
41
            ];
42
        }
43
    }
44
}