Defined stricter model to represent one geo location

This commit is contained in:
Alejandro Celaya
2019-02-17 12:59:55 +01:00
parent 5c5dde48de
commit e2abe23895
19 changed files with 204 additions and 198 deletions

View File

@@ -4,8 +4,8 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core\Entity;
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
use Shlinkio\Shlink\Common\IpGeolocation\Model\Location;
use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface;
use function array_key_exists;
class VisitLocation extends AbstractEntity implements VisitLocationInterface
{
@@ -24,9 +24,9 @@ class VisitLocation extends AbstractEntity implements VisitLocationInterface
/** @var string */
private $timezone;
public function __construct(array $locationInfo)
public function __construct(Location $location)
{
$this->exchangeArray($locationInfo);
$this->exchangeLocationInfo($location);
}
public function getCountryName(): string
@@ -49,32 +49,15 @@ class VisitLocation extends AbstractEntity implements VisitLocationInterface
return $this->cityName ?? '';
}
/**
* Exchange internal values from provided array
*/
private function exchangeArray(array $array): void
private function exchangeLocationInfo(Location $info): void
{
if (array_key_exists('country_code', $array)) {
$this->countryCode = (string) $array['country_code'];
}
if (array_key_exists('country_name', $array)) {
$this->countryName = (string) $array['country_name'];
}
if (array_key_exists('region_name', $array)) {
$this->regionName = (string) $array['region_name'];
}
if (array_key_exists('city', $array)) {
$this->cityName = (string) $array['city'];
}
if (array_key_exists('latitude', $array)) {
$this->latitude = (string) $array['latitude'];
}
if (array_key_exists('longitude', $array)) {
$this->longitude = (string) $array['longitude'];
}
if (array_key_exists('time_zone', $array)) {
$this->timezone = (string) $array['time_zone'];
}
$this->countryCode = $info->countryCode();
$this->countryName = $info->countryName();
$this->regionName = $info->regionName();
$this->cityName = $info->city();
$this->latitude = (string) $info->latitude();
$this->longitude = (string) $info->longitude();
$this->timezone = $info->timeZone();
}
public function jsonSerialize(): array