33namespace ProgrammatorDev \OpenWeatherMap \Endpoint ;
44
55use Http \Client \Exception ;
6+ use ProgrammatorDev \OpenWeatherMap \Endpoint \Util \ValidationTrait ;
67use ProgrammatorDev \OpenWeatherMap \Entity \Geocoding \ZipCodeLocation ;
78use ProgrammatorDev \OpenWeatherMap \Entity \Location ;
89use ProgrammatorDev \OpenWeatherMap \Exception \ApiErrorException ;
9- use ProgrammatorDev \OpenWeatherMap \Util \CreateEntityListTrait ;
10+ use ProgrammatorDev \OpenWeatherMap \Util \EntityListTrait ;
1011use ProgrammatorDev \YetAnotherPhpValidator \Exception \ValidationException ;
11- use ProgrammatorDev \YetAnotherPhpValidator \Validator ;
1212
1313class GeocodingEndpoint extends AbstractEndpoint
1414{
15- use CreateEntityListTrait;
15+ use ValidationTrait;
16+ use EntityListTrait;
1617
1718 private const NUM_RESULTS = 5 ;
1819
@@ -26,8 +27,8 @@ class GeocodingEndpoint extends AbstractEndpoint
2627 */
2728 public function getByLocationName (string $ locationName , int $ numResults = self ::NUM_RESULTS ): array
2829 {
29- Validator:: notBlank ()-> assert ($ locationName , 'locationName ' );
30- Validator:: greaterThan ( 0 )-> assert ($ numResults, ' numResults ' );
30+ $ this -> validateSearchQuery ($ locationName , 'locationName ' );
31+ $ this -> validateNumResults ($ numResults );
3132
3233 $ data = $ this ->sendRequest (
3334 method: 'GET ' ,
@@ -38,7 +39,7 @@ public function getByLocationName(string $locationName, int $numResults = self::
3839 ]
3940 );
4041
41- return $ this ->createEntityList ($ data , Location::class);
42+ return $ this ->createEntityList (Location::class, $ data );
4243 }
4344
4445 /**
@@ -48,8 +49,8 @@ public function getByLocationName(string $locationName, int $numResults = self::
4849 */
4950 public function getByZipCode (string $ zipCode , string $ countryCode ): ZipCodeLocation
5051 {
51- Validator:: notBlank ()-> assert ($ zipCode , 'zipCode ' );
52- Validator:: country ()-> assert ($ countryCode, ' countryCode ' );
52+ $ this -> validateSearchQuery ($ zipCode , 'zipCode ' );
53+ $ this -> validateCountryCode ($ countryCode );
5354
5455 $ data = $ this ->sendRequest (
5556 method: 'GET ' ,
@@ -70,9 +71,8 @@ public function getByZipCode(string $zipCode, string $countryCode): ZipCodeLocat
7071 */
7172 public function getByCoordinate (float $ latitude , float $ longitude , int $ numResults = self ::NUM_RESULTS ): array
7273 {
73- Validator::range (-90 , 90 )->assert ($ latitude , 'latitude ' );
74- Validator::range (-180 , 180 )->assert ($ longitude , 'longitude ' );
75- Validator::greaterThan (0 )->assert ($ numResults , 'numResults ' );
74+ $ this ->validateCoordinate ($ latitude , $ longitude );
75+ $ this ->validateNumResults ($ numResults );
7676
7777 $ data = $ this ->sendRequest (
7878 method: 'GET ' ,
@@ -84,6 +84,6 @@ public function getByCoordinate(float $latitude, float $longitude, int $numResul
8484 ]
8585 );
8686
87- return $ this ->createEntityList ($ data , Location::class);
87+ return $ this ->createEntityList (Location::class, $ data );
8888 }
8989}
0 commit comments