Skip to content

Commit 9ed3b8a

Browse files
committed
chore: updated Weather endpoint validation
1 parent bab23d3 commit 9ed3b8a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Endpoint/WeatherEndpoint.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
use ProgrammatorDev\OpenWeatherMap\Exception\TooManyRequestsException;
1313
use ProgrammatorDev\OpenWeatherMap\Exception\UnauthorizedException;
1414
use ProgrammatorDev\OpenWeatherMap\Exception\UnexpectedErrorException;
15-
use ProgrammatorDev\OpenWeatherMap\Exception\ValidationException;
1615
use ProgrammatorDev\OpenWeatherMap\Validator\CoordinateValidatorTrait;
1716
use ProgrammatorDev\OpenWeatherMap\Validator\GreaterThanValidatorTrait;
17+
use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
18+
use ProgrammatorDev\YetAnotherPhpValidator\Validator;
1819

1920
class WeatherEndpoint extends AbstractEndpoint
2021
{
@@ -40,7 +41,8 @@ class WeatherEndpoint extends AbstractEndpoint
4041
*/
4142
public function getCurrent(float $latitude, float $longitude): WeatherLocation
4243
{
43-
$this->validateCoordinate($latitude, $longitude);
44+
Validator::range(-90, 90)->assert($latitude, 'latitude');
45+
Validator::range(-180, 180)->assert($longitude, 'longitude');
4446

4547
$data = $this->sendRequest(
4648
method: 'GET',
@@ -67,8 +69,9 @@ public function getCurrent(float $latitude, float $longitude): WeatherLocation
6769
*/
6870
public function getForecast(float $latitude, float $longitude, int $numResults = self::NUM_RESULTS): WeatherLocationList
6971
{
70-
$this->validateCoordinate($latitude, $longitude);
71-
$this->validateGreaterThan('numResults', $numResults, 0);
72+
Validator::range(-90, 90)->assert($latitude, 'latitude');
73+
Validator::range(-180, 180)->assert($longitude, 'longitude');
74+
Validator::greaterThan(0)->assert($numResults, 'numResults');
7275

7376
$data = $this->sendRequest(
7477
method: 'GET',

0 commit comments

Comments
 (0)