Completed
Push — master ( 235830...d4758b )
by Alejandro
15s queued 11s
created

VisitLocation   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Test Coverage

Coverage 57.58%

Importance

Changes 0
Metric Value
eloc 34
dl 0
loc 101
ccs 19
cts 33
cp 0.5758
rs 10
c 0
b 0
f 0
wmc 14

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getLongitude() 0 3 1
A jsonSerialize() 0 10 1
A __construct() 0 3 1
A getLatitude() 0 3 1
A getCountryName() 0 3 1
B exchangeArray() 0 22 8
A getCityName() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\Core\Entity;
5
6
use Doctrine\ORM\Mapping as ORM;
7
use JsonSerializable;
8
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
9
use function array_key_exists;
10
11
/**
12
 * Class VisitLocation
13
 * @author
14
 * @link
15
 *
16
 * @ORM\Entity()
17
 * @ORM\Table(name="visit_locations")
18
 */
19
class VisitLocation extends AbstractEntity implements JsonSerializable
20
{
21
    /**
22
     * @var string
23
     * @ORM\Column(nullable=true, name="country_code")
24
     */
25
    private $countryCode;
26
    /**
27
     * @var string
28
     * @ORM\Column(nullable=true, name="country_name")
29
     */
30
    private $countryName;
31
    /**
32
     * @var string
33
     * @ORM\Column(nullable=true, name="region_name")
34
     */
35
    private $regionName;
36
    /**
37
     * @var string
38
     * @ORM\Column(nullable=true, name="city_name")
39
     */
40
    private $cityName;
41
    /**
42
     * @var string
43
     * @ORM\Column(nullable=true, name="latitude")
44
     */
45
    private $latitude;
46
    /**
47
     * @var string
48
     * @ORM\Column(nullable=true, name="longitude")
49
     */
50
    private $longitude;
51
    /**
52
     * @var string
53
     * @ORM\Column(nullable=true, name="timezone")
54
     */
55
    private $timezone;
56
57 4
    public function __construct(array $locationInfo)
58
    {
59 4
        $this->exchangeArray($locationInfo);
60
    }
61
62 3
    public function getCountryName(): string
63
    {
64 3
        return $this->countryName ?? '';
65
    }
66
67 1
    public function getLatitude(): string
68
    {
69 1
        return $this->latitude ?? '';
70
    }
71
72 1
    public function getLongitude(): string
73
    {
74 1
        return $this->longitude ?? '';
75
    }
76
77
    public function getCityName(): string
78
    {
79
        return $this->cityName ?? '';
80
    }
81
82
    /**
83
     * Exchange internal values from provided array
84
     */
85 4
    private function exchangeArray(array $array): void
86
    {
87 4
        if (array_key_exists('country_code', $array)) {
88
            $this->countryCode = (string) $array['country_code'];
89
        }
90 4
        if (array_key_exists('country_name', $array)) {
91 1
            $this->countryName = (string) $array['country_name'];
92
        }
93 4
        if (array_key_exists('region_name', $array)) {
94
            $this->regionName = (string) $array['region_name'];
95
        }
96 4
        if (array_key_exists('city', $array)) {
97
            $this->cityName = (string) $array['city'];
98
        }
99 4
        if (array_key_exists('latitude', $array)) {
100 1
            $this->latitude = (string) $array['latitude'];
101
        }
102 4
        if (array_key_exists('longitude', $array)) {
103 1
            $this->longitude = (string) $array['longitude'];
104
        }
105 4
        if (array_key_exists('time_zone', $array)) {
106
            $this->timezone = (string) $array['time_zone'];
107
        }
108
    }
109
110
    public function jsonSerialize(): array
111
    {
112
        return [
113
            'countryCode' => $this->countryCode,
114
            'countryName' => $this->countryName,
115
            'regionName' => $this->regionName,
116
            'cityName' => $this->cityName,
117
            'latitude' => $this->latitude,
118
            'longitude' => $this->longitude,
119
            'timezone' => $this->timezone,
120
        ];
121
    }
122
}
123