Lines
100.00%
4 / 4
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| GeoLocation | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 3 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 3 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Contracts\Sun; | |
| 6 | ||
| 7 | use Stewart\Contracts\Exception\SunError; | |
| 8 | use Stewart\Contracts\Exception\SunException; | |
| 9 | ||
| 10 | final readonly class GeoLocation | |
| 11 | { | |
| 12 | private const int LATITUDE_LIMIT = 90; | |
| 13 | private const int LONGITUDE_LIMIT = 180; | |
| 14 | ||
| 15 | /** @throws SunException */ | |
| 16 | public function __construct( | |
| 17 | public float $latitude, | |
| 18 | public float $longitude, | |
| 19 | public float $elevationMeters = 0.0, | |
| 20 | ) { | |
| 21 | if (abs($latitude) > self::LATITUDE_LIMIT) { | |
| 22 | throw SunException::createForReason(SunError::CoordinateOutOfRange, coordinate: 'latitude', value: $latitude, limit: self::LATITUDE_LIMIT); | |
| 23 | } | |
| 24 | ||
| 25 | if (abs($longitude) > self::LONGITUDE_LIMIT) { | |
| 26 | throw SunException::createForReason(SunError::CoordinateOutOfRange, coordinate: 'longitude', value: $longitude, limit: self::LONGITUDE_LIMIT); | |
| 27 | } | |
| 28 | } | |
| 29 | } |