Completed
Push — develop ( 8109ce...b15e90 )
by Alejandro
17s queued 12s
created

VisitLocation   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 61.53%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 14
eloc 39
dl 0
loc 72
ccs 24
cts 39
cp 0.6153
rs 10
c 1
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getLongitude() 0 3 1
A jsonSerialize() 0 11 1
A __construct() 0 3 1
A isEmpty() 0 3 1
A getCityName() 0 3 1
A getLatitude() 0 3 1
B exchangeLocationInfo() 0 17 7
A getCountryName() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Core\Entity;
6
7
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
8
use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface;
9
use Shlinkio\Shlink\IpGeolocation\Model\Location;
10
11
class VisitLocation extends AbstractEntity implements VisitLocationInterface
12
{
13
    private string $countryCode;
14
    private string $countryName;
15
    private string $regionName;
16
    private string $cityName;
17
    private float $latitude;
18
    private float $longitude;
19
    private string $timezone;
20
    private bool $isEmpty;
21
22 28
    public function __construct(Location $location)
23
    {
24 28
        $this->exchangeLocationInfo($location);
25 28
    }
26
27 1
    public function getCountryName(): string
28
    {
29 1
        return $this->countryName;
30
    }
31
32
    public function getLatitude(): float
33
    {
34
        return $this->latitude;
35
    }
36
37
    public function getLongitude(): float
38
    {
39
        return $this->longitude;
40
    }
41
42
    public function getCityName(): string
43
    {
44
        return $this->cityName;
45
    }
46
47 11
    public function isEmpty(): bool
48
    {
49 11
        return $this->isEmpty;
50
    }
51
52 28
    private function exchangeLocationInfo(Location $info): void
53
    {
54 28
        $this->countryCode = $info->countryCode();
55 28
        $this->countryName = $info->countryName();
56 28
        $this->regionName = $info->regionName();
57 28
        $this->cityName = $info->city();
58 28
        $this->latitude = $info->latitude();
59 28
        $this->longitude = $info->longitude();
60 28
        $this->timezone = $info->timeZone();
61 28
        $this->isEmpty = (
62 28
            $this->countryCode === '' &&
63 28
            $this->countryName === '' &&
64 28
            $this->regionName === '' &&
65 28
            $this->cityName === '' &&
66 28
            $this->latitude === 0.0 &&
0 ignored issues
show
introduced by
The condition $this->latitude === 0.0 is always false.
Loading history...
67 28
            $this->longitude === 0.0 &&
68 21
            $this->timezone === ''
69
        );
70 28
    }
71
72
    public function jsonSerialize(): array
73
    {
74
        return [
75
            'countryCode' => $this->countryCode,
76
            'countryName' => $this->countryName,
77
            'regionName' => $this->regionName,
78
            'cityName' => $this->cityName,
79
            'latitude' => $this->latitude,
80
            'longitude' => $this->longitude,
81
            'timezone' => $this->timezone,
82
            'isEmpty' => $this->isEmpty,
83
        ];
84
    }
85
}
86