Location::__construct()   F
last analyzed

Complexity

Conditions 15
Paths 990

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 1.7638
c 0
b 0
f 0
cc 15
nc 990
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace SmartyStreets\Location;
4
5
class Location
6
{
7
    private $street;
8
    private $streetNumber;
9
    private $locality;
10
    private $postcode;
11
    private $country = 'Switzerland';
12
    private $latitude;
13
    private $longitude;
14
    private $verified = false;
15
16
    public function __construct($locationArray)
17
    {
18
        $this->verified = (isset($locationArray['analysis']) && $locationArray['analysis']['verification_status'] && $locationArray['analysis']['verification_status'] == 'Verified') ? true : false;
19
20
        if (isset($locationArray['components']) && is_array($locationArray['components'])) {
21
            $this->street = isset($locationArray['components']['thoroughfare']) ? $locationArray['components']['thoroughfare'] : '';
22
            $this->streetNumber = isset($locationArray['components']['premise']) ? $locationArray['components']['premise'] : '';
23
            $this->locality = isset($locationArray['components']['locality']) ? $locationArray['components']['locality'] : '';
24
            $this->postcode = isset($locationArray['components']['postal_code']) ? $locationArray['components']['postal_code'] : '';
25
            $this->country = isset($locationArray['components']['country_iso_3']) ? $locationArray['components']['country_iso_3'] : '';
26
        }
27
28
        if (isset($locationArray['metadata']) && is_array($locationArray['metadata'])) {
29
            $this->latitude = isset($locationArray['metadata']['latitude']) ? $locationArray['metadata']['latitude'] : '';
30
            $this->longitude = isset($locationArray['metadata']['longitude']) ? $locationArray['metadata']['longitude'] : '';
31
        }
32
    }
33
34
    public function getStreet()
35
    {
36
        return $this->street;
37
    }
38
39
    public function getStreetNumber()
40
    {
41
        return $this->streetNumber;
42
    }
43
44
    public function getLocality()
45
    {
46
        return $this->locality;
47
    }
48
49
    public function getPostalCode()
50
    {
51
        return $this->postcode;
52
    }
53
54
    public function getCountry()
55
    {
56
        return $this->country;
57
    }
58
59
    public function getLatitude()
60
    {
61
        return $this->latitude;
62
    }
63
64
    public function getLongitude()
65
    {
66
        return $this->longitude;
67
    }
68
69
    public function getIsVerified()
70
    {
71
        return $this->verified;
72
    }
73
}
74