1010use ProgrammatorDev \OpenWeatherMap \Exception \TooManyRequestsException ;
1111use ProgrammatorDev \OpenWeatherMap \Exception \UnauthorizedException ;
1212use ProgrammatorDev \OpenWeatherMap \Exception \UnexpectedErrorException ;
13- use ProgrammatorDev \OpenWeatherMap \Exception \ValidationException ;
14- use ProgrammatorDev \OpenWeatherMap \Validator \CoordinateValidatorTrait ;
15- use ProgrammatorDev \OpenWeatherMap \Validator \LessThanValidatorTrait ;
16- use ProgrammatorDev \OpenWeatherMap \Validator \RangeValidatorTrait ;
13+ use ProgrammatorDev \YetAnotherPhpValidator \Exception \ValidationException ;
14+ use ProgrammatorDev \YetAnotherPhpValidator \Validator ;
1715
1816class AirPollutionEndpoint extends AbstractEndpoint
1917{
20- use CoordinateValidatorTrait;
21- use LessThanValidatorTrait;
22- use RangeValidatorTrait;
23-
2418 private string $ urlAirPollution = 'https://api.openweathermap.org/data/2.5/air_pollution ' ;
2519
2620 private string $ urlAirPollutionForecast = 'https://api.openweathermap.org/data/2.5/air_pollution/forecast ' ;
@@ -38,7 +32,8 @@ class AirPollutionEndpoint extends AbstractEndpoint
3832 */
3933 public function getCurrent (float $ latitude , float $ longitude ): AirPollutionLocation
4034 {
41- $ this ->validateCoordinate ($ latitude , $ longitude );
35+ Validator::range (-90 , 90 )->assert ($ latitude , 'latitude ' );
36+ Validator::range (-180 , 180 )->assert ($ longitude , 'longitude ' );
4237
4338 $ data = $ this ->sendRequest (
4439 method: 'GET ' ,
@@ -63,7 +58,8 @@ public function getCurrent(float $latitude, float $longitude): AirPollutionLocat
6358 */
6459 public function getForecast (float $ latitude , float $ longitude ): AirPollutionLocationList
6560 {
66- $ this ->validateCoordinate ($ latitude , $ longitude );
61+ Validator::range (-90 , 90 )->assert ($ latitude , 'latitude ' );
62+ Validator::range (-180 , 180 )->assert ($ longitude , 'longitude ' );
6763
6864 $ data = $ this ->sendRequest (
6965 method: 'GET ' ,
@@ -93,10 +89,10 @@ public function getHistory(
9389 \DateTimeInterface $ endDate
9490 ): AirPollutionLocationList
9591 {
96- $ this -> validateCoordinate ($ latitude , $ longitude );
97- $ this -> validateLessThan ( ' startDate ' , $ startDate , new \ DateTimeImmutable ( ' now ' ) );
98- $ this -> validateLessThan ( ' endDate ' , $ endDate , new \DateTimeImmutable ('now ' ));
99- $ this -> validateRange ( ' startDate ' , 'endDate ' , $ startDate , $ endDate );
92+ Validator:: range (- 90 , 90 )-> assert ($ latitude , ' latitude ' );
93+ Validator:: range (- 180 , 180 )-> assert ( $ longitude , ' longitude ' );
94+ Validator:: lessThan ( new \DateTime ('now ' ))-> assert ( $ endDate , ' endDate ' );
95+ Validator:: greaterThan ( $ startDate )-> assert ( $ endDate , 'endDate ' );
10096
10197 $ timezoneUtc = new \DateTimeZone ('UTC ' );
10298
0 commit comments