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