__("Australia"), "CA" => __("Canada"), "DK" => __("Denmark"), "FR" => __("France"), "DE" => __("Germany"), "JP" => __("Japan"), "NZ" => __("New Zealand"), "NO" => __("Norway"), "PL" => __("Poland"), "ES" => __("Spain"), "SE" => __("Sweden"), "CH" => __("Switzerland"), "GB" => __("United Kingdom"), "US" => __("United States"), ]; } // Magic methods public function __toString(): string { $county_parts = array_filter([$this->county, $this->state, $this->postal_code]); $lines = array_filter([ $this->address_1, $this->address_2, $this->city, implode(", ", $county_parts), $this->getDisplayCountry() ]); return implode("\n", $lines); } // Object methods public function hasGeolocation(): bool { return isset($this->latitude, $this->longitude); } public function geocode(): ?array { try { $results = Geolocation::geocode($this->postal_code); $result = $results[0]; $this->latitude = $result->geometry->location->lat; $this->longitude = $result->geometry->location->lng; return [$this->latitude, $this->longitude]; } catch(Exception $e) { return null; } } private function getDisplayCountry(): string { if($this->country) { return self::getCountryOptions()[$this->country] ?? ""; } return ""; } }