| @@ 10-58 (lines=49) @@ | ||
| 7 | use Marek\OpenWeatherMap\API\Exception\InvalidArgumentException; |
|
| 8 | use Marek\OpenWeatherMap\API\Value\Parameter\GetParameterInterface; |
|
| 9 | ||
| 10 | class Latitude implements GetParameterInterface |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @var float |
|
| 14 | */ |
|
| 15 | protected $latitude; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * Latitude constructor. |
|
| 19 | * |
|
| 20 | * @param float $latitude |
|
| 21 | */ |
|
| 22 | public function __construct(float $latitude) |
|
| 23 | { |
|
| 24 | $this->validate($latitude); |
|
| 25 | $this->latitude = $latitude; |
|
| 26 | } |
|
| 27 | ||
| 28 | /** |
|
| 29 | * @return float |
|
| 30 | */ |
|
| 31 | public function getLatitude() |
|
| 32 | { |
|
| 33 | return $this->latitude; |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * {@inheritdoc} |
|
| 38 | */ |
|
| 39 | public function getGetParameterValue() |
|
| 40 | { |
|
| 41 | return (string) $this->latitude; |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * {@inheritdoc} |
|
| 46 | */ |
|
| 47 | public function getGetParameterName() |
|
| 48 | { |
|
| 49 | return 'lat'; |
|
| 50 | } |
|
| 51 | ||
| 52 | protected function validate(float $latitude): void |
|
| 53 | { |
|
| 54 | if ($latitude < -90 || $latitude > 90) { |
|
| 55 | throw new InvalidArgumentException((string)$latitude, 'latitude', self::class); |
|
| 56 | } |
|
| 57 | } |
|
| 58 | } |
|
| 59 | ||
| @@ 10-58 (lines=49) @@ | ||
| 7 | use Marek\OpenWeatherMap\API\Exception\InvalidArgumentException; |
|
| 8 | use Marek\OpenWeatherMap\API\Value\Parameter\GetParameterInterface; |
|
| 9 | ||
| 10 | class Longitude implements GetParameterInterface |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @var float |
|
| 14 | */ |
|
| 15 | protected $longitude; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * Longitude constructor. |
|
| 19 | * |
|
| 20 | * @param float $longitude |
|
| 21 | */ |
|
| 22 | public function __construct(float $longitude) |
|
| 23 | { |
|
| 24 | $this->validate($longitude); |
|
| 25 | $this->longitude = $longitude; |
|
| 26 | } |
|
| 27 | ||
| 28 | /** |
|
| 29 | * @return float |
|
| 30 | */ |
|
| 31 | public function getLongitude() |
|
| 32 | { |
|
| 33 | return $this->longitude; |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * {@inheritdoc} |
|
| 38 | */ |
|
| 39 | public function getGetParameterValue() |
|
| 40 | { |
|
| 41 | return (string) $this->longitude; |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * {@inheritdoc} |
|
| 46 | */ |
|
| 47 | public function getGetParameterName() |
|
| 48 | { |
|
| 49 | return 'lon'; |
|
| 50 | } |
|
| 51 | ||
| 52 | protected function validate(float $longitude): void |
|
| 53 | { |
|
| 54 | if ($longitude < -180 || $longitude > 180) { |
|
| 55 | throw new InvalidArgumentException((string)$longitude, 'longitude', self::class); |
|
| 56 | } |
|
| 57 | } |
|
| 58 | } |
|
| 59 | ||