Skip to content

Commit ca3cb22

Browse files
committed
chore: update Geocoding endpoint validation
1 parent ecffab8 commit ca3cb22

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

src/Endpoint/GeocodingEndpoint.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,13 @@
1010
use ProgrammatorDev\OpenWeatherMap\Exception\TooManyRequestsException;
1111
use ProgrammatorDev\OpenWeatherMap\Exception\UnauthorizedException;
1212
use ProgrammatorDev\OpenWeatherMap\Exception\UnexpectedErrorException;
13-
use ProgrammatorDev\OpenWeatherMap\Exception\ValidationException;
1413
use ProgrammatorDev\OpenWeatherMap\Util\CreateEntityListTrait;
15-
use ProgrammatorDev\OpenWeatherMap\Validator\BlankValidatorTrait;
16-
use ProgrammatorDev\OpenWeatherMap\Validator\CoordinateValidatorTrait;
17-
use ProgrammatorDev\OpenWeatherMap\Validator\GreaterThanValidatorTrait;
14+
use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
15+
use ProgrammatorDev\YetAnotherPhpValidator\Validator;
1816

1917
class GeocodingEndpoint extends AbstractEndpoint
2018
{
2119
use CreateEntityListTrait;
22-
use BlankValidatorTrait;
23-
use CoordinateValidatorTrait;
24-
use GreaterThanValidatorTrait;
2520

2621
private const NUM_RESULTS = 5;
2722

@@ -45,8 +40,8 @@ class GeocodingEndpoint extends AbstractEndpoint
4540
*/
4641
public function getByLocationName(string $locationName, int $numResults = self::NUM_RESULTS): array
4742
{
48-
$this->validateBlank('locationName', $locationName);
49-
$this->validateGreaterThan('numResults', $numResults, 0);
43+
Validator::notBlank()->assert($locationName, 'locationName');
44+
Validator::greaterThan(0)->assert($numResults, 'numResults');
5045

5146
$data = $this->sendRequest(
5247
method: 'GET',
@@ -71,8 +66,8 @@ public function getByLocationName(string $locationName, int $numResults = self::
7166
*/
7267
public function getByZipCode(string $zipCode, string $countryCode): ZipCodeLocation
7368
{
74-
$this->validateBlank('zipCode', $zipCode);
75-
$this->validateBlank('countryCode', $countryCode);
69+
Validator::notBlank()->assert($zipCode, 'zipCode');
70+
Validator::notBlank()->assert($countryCode, 'countryCode');
7671

7772
$data = $this->sendRequest(
7873
method: 'GET',
@@ -97,8 +92,9 @@ public function getByZipCode(string $zipCode, string $countryCode): ZipCodeLocat
9792
*/
9893
public function getByCoordinate(float $latitude, float $longitude, int $numResults = self::NUM_RESULTS): array
9994
{
100-
$this->validateCoordinate($latitude, $longitude);
101-
$this->validateGreaterThan('numResults', $numResults, 0);
95+
Validator::range(-90, 90)->assert($latitude, 'latitude');
96+
Validator::range(-180, 180)->assert($longitude, 'longitude');
97+
Validator::greaterThan(0)->assert($numResults, 'numResults');
10298

10399
$data = $this->sendRequest(
104100
method: 'GET',

tests/GeocodingEndpointTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
use ProgrammatorDev\OpenWeatherMap\Entity\Coordinate;
99
use ProgrammatorDev\OpenWeatherMap\Entity\Geocoding\ZipCodeLocation;
1010
use ProgrammatorDev\OpenWeatherMap\Entity\Location;
11-
use ProgrammatorDev\OpenWeatherMap\Exception\ValidationException;
1211
use ProgrammatorDev\OpenWeatherMap\Test\DataProvider\InvalidParamDataProvider;
12+
use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
1313

1414
class GeocodingEndpointTest extends AbstractTest
1515
{

0 commit comments

Comments
 (0)