Location   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 102
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A toString() 0 4 1
A applyCountry() 0 9 2
A getCountryName() 0 4 1
A setCountryName() 0 5 1
A getState() 0 4 1
A setState() 0 5 1
A getCity() 0 4 1
A setCity() 0 5 1
1
<?php
2
/**
3
 * Slince shipment tracker library
4
 * @author Tao <[email protected]>
5
 */
6
7
namespace Slince\ShipmentTracking\Common\Location;
8
9
use Rinvex\Country\Country;
10
use Slince\ShipmentTracking\Foundation\Location\AbstractLocation;
11
use Exception;
12
13
class Location extends AbstractLocation
14
{
15
    /**
16
     * @var string
17
     */
18
    protected $countryName;
19
20
    /**
21
     * @var string
22
     */
23
    protected $state;
24
25
    /**
26
     * @var string
27
     */
28
    protected $city;
29
30
    /**
31
     * @var Country
32
     */
33
    protected $country;
34
35
    public function __construct($countryCode, $state, $city)
36
    {
37
        $countryCode = strtolower($countryCode);
38
        $countryCode && $this->applyCountry($countryCode);
39
        $this->state = $state;
40
        $this->city = $city;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function toString()
47
    {
48
        return trim(implode(' ', [$this->city, $this->state, $this->countryName]));
49
    }
50
51
    protected function applyCountry($countryCode)
52
    {
53
        try {
54
            $this->country = country($countryCode);
0 ignored issues
show
Documentation Bug introduced by
It seems like country($countryCode) can also be of type array. However, the property $country is declared as type object<Rinvex\Country\Country>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
55
            $this->countryName = $this->country->getName();
56
        } catch (Exception $exception) {
57
            $this->countryName = $countryCode;
58
        }
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    public function getCountryName()
65
    {
66
        return $this->countryName;
67
    }
68
69
    /**
70
     * @param string $countryName
71
     * @return Location
72
     */
73
    public function setCountryName($countryName)
74
    {
75
        $this->countryName = $countryName;
76
        return $this;
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    public function getState()
83
    {
84
        return $this->state;
85
    }
86
87
    /**
88
     * @param string $state
89
     * @return Location
90
     */
91
    public function setState($state)
92
    {
93
        $this->state = $state;
94
        return $this;
95
    }
96
97
    /**
98
     * @return string
99
     */
100
    public function getCity()
101
    {
102
        return $this->city;
103
    }
104
105
    /**
106
     * @param string $city
107
     * @return Location
108
     */
109
    public function setCity($city)
110
    {
111
        $this->city = $city;
112
        return $this;
113
    }
114
}