10
10
use ProgrammatorDev \OpenWeatherMap \Exception \TooManyRequestsException ;
11
11
use ProgrammatorDev \OpenWeatherMap \Exception \UnauthorizedException ;
12
12
use 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 ;
17
15
18
16
class AirPollutionEndpoint extends AbstractEndpoint
19
17
{
20
- use CoordinateValidatorTrait;
21
- use LessThanValidatorTrait;
22
- use RangeValidatorTrait;
23
-
24
18
private string $ urlAirPollution = 'https://api.openweathermap.org/data/2.5/air_pollution ' ;
25
19
26
20
private string $ urlAirPollutionForecast = 'https://api.openweathermap.org/data/2.5/air_pollution/forecast ' ;
@@ -38,7 +32,8 @@ class AirPollutionEndpoint extends AbstractEndpoint
38
32
*/
39
33
public function getCurrent (float $ latitude , float $ longitude ): AirPollutionLocation
40
34
{
41
- $ this ->validateCoordinate ($ latitude , $ longitude );
35
+ Validator::range (-90 , 90 )->assert ($ latitude , 'latitude ' );
36
+ Validator::range (-180 , 180 )->assert ($ longitude , 'longitude ' );
42
37
43
38
$ data = $ this ->sendRequest (
44
39
method: 'GET ' ,
@@ -63,7 +58,8 @@ public function getCurrent(float $latitude, float $longitude): AirPollutionLocat
63
58
*/
64
59
public function getForecast (float $ latitude , float $ longitude ): AirPollutionLocationList
65
60
{
66
- $ this ->validateCoordinate ($ latitude , $ longitude );
61
+ Validator::range (-90 , 90 )->assert ($ latitude , 'latitude ' );
62
+ Validator::range (-180 , 180 )->assert ($ longitude , 'longitude ' );
67
63
68
64
$ data = $ this ->sendRequest (
69
65
method: 'GET ' ,
@@ -93,10 +89,10 @@ public function getHistory(
93
89
\DateTimeInterface $ endDate
94
90
): AirPollutionLocationList
95
91
{
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 ' );
100
96
101
97
$ timezoneUtc = new \DateTimeZone ('UTC ' );
102
98
0 commit comments