Completed
Pull Request — master (#232)
by Alejandro
05:16
created

VisitLocation::exchangeArray()   B

Complexity

Conditions 8
Paths 128

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 9.953

Importance

Changes 0
Metric Value
cc 8
nc 128
nop 1
dl 0
loc 24
ccs 11
cts 16
cp 0.6875
crap 9.953
rs 8.2111
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\Core\Entity;
5
6
use Doctrine\ORM\Mapping as ORM;
7
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
8
use Zend\Stdlib\ArraySerializableInterface;
9
10
/**
11
 * Class VisitLocation
12
 * @author
13
 * @link
14
 *
15
 * @ORM\Entity()
16
 * @ORM\Table(name="visit_locations")
17
 */
18
class VisitLocation extends AbstractEntity implements ArraySerializableInterface, \JsonSerializable
19
{
20
    /**
21
     * @var string
22
     * @ORM\Column(nullable=true)
23
     */
24
    private $countryCode;
25
    /**
26
     * @var string
27
     * @ORM\Column(nullable=true)
28
     */
29
    private $countryName;
30
    /**
31
     * @var string
32
     * @ORM\Column(nullable=true)
33
     */
34
    private $regionName;
35
    /**
36
     * @var string
37
     * @ORM\Column(nullable=true)
38
     */
39
    private $cityName;
40
    /**
41
     * @var string
42
     * @ORM\Column(nullable=true)
43
     */
44
    private $latitude;
45
    /**
46
     * @var string
47
     * @ORM\Column(nullable=true)
48
     */
49
    private $longitude;
50
    /**
51
     * @var string
52
     * @ORM\Column(nullable=true)
53
     */
54
    private $timezone;
55
56
    public function getCountryCode(): string
57
    {
58
        return $this->countryCode ?? '';
59
    }
60
61
    public function setCountryCode(string $countryCode)
62
    {
63
        $this->countryCode = $countryCode;
64
        return $this;
65
    }
66
67 1
    public function getCountryName(): string
68
    {
69 1
        return $this->countryName ?? '';
70
    }
71
72 1
    public function setCountryName(string $countryName): self
73
    {
74 1
        $this->countryName = $countryName;
75 1
        return $this;
76
    }
77
78
    public function getRegionName(): string
79
    {
80
        return $this->regionName ?? '';
81
    }
82
83
    public function setRegionName(string $regionName): self
84
    {
85
        $this->regionName = $regionName;
86
        return $this;
87
    }
88
89 3
    public function getCityName(): string
90
    {
91 3
        return $this->cityName ?? '';
92
    }
93
94
    public function setCityName(string $cityName): self
95
    {
96
        $this->cityName = $cityName;
97
        return $this;
98
    }
99
100 1
    public function getLatitude(): string
101
    {
102 1
        return $this->latitude ?? '';
103
    }
104
105 1
    public function setLatitude(string $latitude): self
106
    {
107 1
        $this->latitude = $latitude;
108 1
        return $this;
109
    }
110
111 1
    public function getLongitude(): string
112
    {
113 1
        return $this->longitude ?? '';
114
    }
115
116 1
    public function setLongitude(string $longitude): self
117
    {
118 1
        $this->longitude = $longitude;
119 1
        return $this;
120
    }
121
122
    public function getTimezone(): string
123
    {
124
        return $this->timezone ?? '';
125
    }
126
127
    public function setTimezone(string $timezone): self
128
    {
129
        $this->timezone = $timezone;
130
        return $this;
131
    }
132
133
    /**
134
     * Exchange internal values from provided array
135
     */
136 4
    public function exchangeArray(array $array): void
137
    {
138 4
        if (\array_key_exists('country_code', $array)) {
139
            $this->setCountryCode((string) $array['country_code']);
140
        }
141 4
        if (\array_key_exists('country_name', $array)) {
142
            $this->setCountryName((string) $array['country_name']);
143
        }
144 4
        if (\array_key_exists('region_name', $array)) {
145
            $this->setRegionName((string) $array['region_name']);
146
        }
147 4
        if (\array_key_exists('city', $array)) {
148
            $this->setCityName((string) $array['city']);
149
        }
150 4
        if (\array_key_exists('latitude', $array)) {
151 1
            $this->setLatitude((string) $array['latitude']);
152
        }
153 4
        if (\array_key_exists('longitude', $array)) {
154 1
            $this->setLongitude((string) $array['longitude']);
155
        }
156 4
        if (\array_key_exists('time_zone', $array)) {
157
            $this->setTimezone((string) $array['time_zone']);
158
        }
159 4
    }
160
161
    /**
162
     * Return an array representation of the object
163
     */
164
    public function getArrayCopy(): array
165
    {
166
        return [
167
            'countryCode' => $this->countryCode,
168
            'countryName' => $this->countryName,
169
            'regionName' => $this->regionName,
170
            'cityName' => $this->cityName,
171
            'latitude' => $this->latitude,
172
            'longitude' => $this->longitude,
173
            'timezone' => $this->timezone,
174
        ];
175
    }
176
177
    public function jsonSerialize(): array
178
    {
179
        return $this->getArrayCopy();
180
    }
181
}
182