*/ protected $subdivisions = []; /** * @ignore */ public function __construct(array $raw, array $locales = ['en']) { parent::__construct($raw, $locales); $this->city = new \WP_Statistics\Dependencies\GeoIp2\Record\City($this->get('city'), $locales); $this->location = new \WP_Statistics\Dependencies\GeoIp2\Record\Location($this->get('location')); $this->postal = new \WP_Statistics\Dependencies\GeoIp2\Record\Postal($this->get('postal')); $this->createSubdivisions($raw, $locales); } private function createSubdivisions(array $raw, array $locales): void { if (!isset($raw['subdivisions'])) { return; } foreach ($raw['subdivisions'] as $sub) { $this->subdivisions[] = new \WP_Statistics\Dependencies\GeoIp2\Record\Subdivision($sub, $locales) ; } } /** * @ignore * * @return mixed */ public function __get(string $attr) { if ($attr === 'mostSpecificSubdivision') { return $this->{$attr}(); } return parent::__get($attr); } /** * @ignore */ public function __isset(string $attr): bool { if ($attr === 'mostSpecificSubdivision') { // We always return a mostSpecificSubdivision, even if it is the // empty subdivision return true; } return parent::__isset($attr); } private function mostSpecificSubdivision(): \WP_Statistics\Dependencies\GeoIp2\Record\Subdivision { return empty($this->subdivisions) ? new \WP_Statistics\Dependencies\GeoIp2\Record\Subdivision([], $this->locales) : end($this->subdivisions); } }