Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| IpLocationDto | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Modules\Map\Domain\Model; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | /** |
| 12 | * Immutable Data Transfer Object representing geolocated IP address coordinates and location metadata. |
| 13 | * |
| 14 | * @package App\Modules\Map\Domain\Model |
| 15 | */ |
| 16 | final readonly class IpLocationDto |
| 17 | { |
| 18 | /** |
| 19 | * @param string $ipAddress Resolved IPv4 or IPv6 address. |
| 20 | * @param float $latitude WGS-84 latitude coordinate. |
| 21 | * @param float $longitude WGS-84 longitude coordinate. |
| 22 | * @param string|null $countryCode ISO 3166-1 alpha-2 country code (e.g. "PL", "DE", "US"). |
| 23 | * @param string|null $countryName Human-readable country name. |
| 24 | * @param string|null $cityName City or locality name. |
| 25 | * @param string|null $timezone Timezone identifier (e.g. "Europe/Warsaw"). |
| 26 | */ |
| 27 | public function __construct( |
| 28 | public string $ipAddress, |
| 29 | public float $latitude, |
| 30 | public float $longitude, |
| 31 | public ?string $countryCode = null, |
| 32 | public ?string $countryName = null, |
| 33 | public ?string $cityName = null, |
| 34 | public ?string $timezone = null, |
| 35 | ) { |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Converts DTO to array representation for JSON API responses. |
| 40 | * |
| 41 | * @return array<string, mixed> |
| 42 | */ |
| 43 | public function toArray(): array |
| 44 | { |
| 45 | return [ |
| 46 | 'ip_address' => $this->ipAddress, |
| 47 | 'latitude' => $this->latitude, |
| 48 | 'longitude' => $this->longitude, |
| 49 | 'country_code' => $this->countryCode, |
| 50 | 'country_name' => $this->countryName, |
| 51 | 'city_name' => $this->cityName, |
| 52 | 'timezone' => $this->timezone, |
| 53 | ]; |
| 54 | } |
| 55 | } |