Skip to content

Commit 04d5e7b

Browse files
author
Mario Blazek
committed
Refactoring
1 parent f1090f8 commit 04d5e7b

19 files changed

Lines changed: 510 additions & 64 deletions

API/OpenWeatherMap/Weather/AirPollutionInterface.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ interface AirPollutionInterface
2020
* @param float $longitude
2121
* @param \DateTime|string $datetime
2222
*
23-
* @return mixed
23+
* @return string
24+
*
25+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
26+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
2427
*/
2528
public function fetchOzoneData($latitude, $longitude, $datetime = 'current');
2629

@@ -31,7 +34,10 @@ public function fetchOzoneData($latitude, $longitude, $datetime = 'current');
3134
* @param float $longitude
3235
* @param \DateTime|string $datetime
3336
*
34-
* @return mixed
37+
* @return string
38+
*
39+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
40+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
3541
*/
3642
public function fetchCarbonMonoxideData($latitude, $longitude, $datetime = 'current');
3743
}

API/OpenWeatherMap/Weather/DailyForecastInterface.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ interface DailyForecastInterface
2020
* @param string $countryCode
2121
* @param int $numberOfDays
2222
*
23-
* @return mixed
23+
* @return string
24+
*
25+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
26+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
2427
*/
2528
public function fetchForecastByCityName($cityName, $countryCode = '', $numberOfDays = 16);
2629

@@ -30,7 +33,10 @@ public function fetchForecastByCityName($cityName, $countryCode = '', $numberOfD
3033
* @param int $cityId
3134
* @param int $numberOfDays
3235
*
33-
* @return mixed
36+
* @return string
37+
*
38+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
39+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
3440
*/
3541
public function fetchForecastByCityId($cityId, $numberOfDays = 16);
3642

@@ -41,7 +47,10 @@ public function fetchForecastByCityId($cityId, $numberOfDays = 16);
4147
* @param float $longitude
4248
* @param int $numberOfDays
4349
*
44-
* @return mixed
50+
* @return string
51+
*
52+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
53+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
4554
*/
4655
public function fetchForecastByCityGeographicCoordinates($latitude, $longitude, $numberOfDays = 16);
4756
}

API/OpenWeatherMap/Weather/HourForecastInterface.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ interface HourForecastInterface
1919
* @param string $cityName
2020
* @param string $countryCode
2121
*
22-
* @return mixed
22+
* @return string
23+
*
24+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
25+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
2326
*/
2427
public function fetchForecastByCityName($cityName, $countryCode = '');
2528

@@ -28,7 +31,10 @@ public function fetchForecastByCityName($cityName, $countryCode = '');
2831
*
2932
* @param int $cityId
3033
*
31-
* @return mixed
34+
* @return string
35+
*
36+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
37+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
3238
*/
3339
public function fetchForecastByCityId($cityId);
3440

@@ -38,7 +44,10 @@ public function fetchForecastByCityId($cityId);
3844
* @param float $latitude
3945
* @param float $longitude
4046
*
41-
* @return mixed
47+
* @return string
48+
*
49+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
50+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
4251
*/
4352
public function fetchForecastByCityGeographicCoordinates($latitude, $longitude);
4453
}

API/OpenWeatherMap/Weather/UltravioletIndexInterface.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ interface UltravioletIndexInterface
2020
* @param float $longitude
2121
* @param \Datetime|string $datetime
2222
*
23-
* @return mixed
23+
* @return string
24+
*
25+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
26+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
2427
*/
2528
public function fetchUltraviletIndex($latitude, $longitude, $datetime = 'current');
2629
}

API/OpenWeatherMap/Weather/WeatherInterface.php

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ interface WeatherInterface
1919
* @param string $cityName
2020
* @param string $countryCode
2121
*
22-
* @return mixed
22+
* @return string
23+
*
24+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
25+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
2326
*/
2427
public function fetchWeatherDataByCityName($cityName, $countryCode = '');
2528

@@ -28,17 +31,23 @@ public function fetchWeatherDataByCityName($cityName, $countryCode = '');
2831
*
2932
* @param int $cityId
3033
*
31-
* @return mixed
34+
* @return string
35+
*
36+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
37+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
3238
*/
3339
public function fetchWeatherDataByCityId($cityId);
3440

3541
/**
3642
* Call current weather data for one location by geographic coordinates
3743
*
38-
* @param int $latitude
39-
* @param int $longitude
44+
* @param float $latitude
45+
* @param float $longitude
4046
*
41-
* @return mixed
47+
* @return string
48+
*
49+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
50+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
4251
*/
4352
public function fetchWeatherDataByGeographicCoordinates($latitude, $longitude);
4453

@@ -49,7 +58,10 @@ public function fetchWeatherDataByGeographicCoordinates($latitude, $longitude);
4958
* @param int $zipCode
5059
* @param string $countryCode
5160
*
52-
* @return mixed
61+
* @return string
62+
*
63+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
64+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
5365
*/
5466
public function fetchWeatherDataByZipCode($zipCode, $countryCode = '');
5567

@@ -59,7 +71,10 @@ public function fetchWeatherDataByZipCode($zipCode, $countryCode = '');
5971
* @param array $boundingBox Longitude-left,latitude-bottom,longitude-right,latitude-top
6072
* @param string $cluster
6173
*
62-
* @return mixed
74+
* @return string
75+
*
76+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
77+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
6378
*/
6479
public function fetchWeatherDataForCitiesWithinRectangleZone(array $boundingBox, $cluster = 'yes');
6580

@@ -71,7 +86,10 @@ public function fetchWeatherDataForCitiesWithinRectangleZone(array $boundingBox,
7186
* @param string $cluster
7287
* @param int $numberOfCities
7388
*
74-
* @return mixed
89+
* @return string
90+
*
91+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
92+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
7593
*/
7694
public function fetchWeatherDataForCitiesInCycle($latitude, $longitude, $cluster = 'yes', $numberOfCities = 10);
7795

@@ -80,7 +98,10 @@ public function fetchWeatherDataForCitiesInCycle($latitude, $longitude, $cluster
8098
*
8199
* @param array $cities
82100
*
83-
* @return mixed
101+
* @return string
102+
*
103+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
104+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
84105
*/
85106
public function fetchWeatherDataForSeveralCityIds(array $cities);
86107
}

API/OpenWeatherMap/Weather/WeatherStationsInterface.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ interface WeatherStationsInterface
1818
*
1919
* @param int $stationId
2020
*
21-
* @return mixed
21+
* @return string
22+
*
23+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
24+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
2225
*/
2326
public function fetchFromOnStationById($stationId);
2427

@@ -29,7 +32,10 @@ public function fetchFromOnStationById($stationId);
2932
* @param string $cluster
3033
* @param int $numberOfStations
3134
*
32-
* @return mixed
35+
* @return string
36+
*
37+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
38+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
3339
*/
3440
public function fetchFromSeveralByRectangleZone(array $boundingBox, $cluster = 'yes', $numberOfStations = 10);
3541

@@ -40,7 +46,10 @@ public function fetchFromSeveralByRectangleZone(array $boundingBox, $cluster = '
4046
* @param float $longitude
4147
* @param int $numberOfStations
4248
*
43-
* @return mixed
49+
* @return string
50+
*
51+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
52+
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
4453
*/
4554
public function fetchFromSeveralByGeoPoint($latitude, $longitude, $numberOfStations = 10);
4655
}

Controller/AirPollutionController.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Netgen\Bundle\OpenWeatherMapBundle\Controller;
44

55
use Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\AirPollutionInterface;
6+
use Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException;
7+
use Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException;
68
use Symfony\Component\HttpFoundation\Response;
79
use DateTime;
810

@@ -47,9 +49,18 @@ public function getOzoneData($latitude, $longitude, $datetime = 'current')
4749
}
4850
}
4951

50-
$data = $this->airPollution->fetchOzoneData($latitude, $longitude, $datetime);
52+
$response = new Response();
5153

52-
return new Response($data);
54+
try {
55+
$data = $this->airPollution->fetchOzoneData($latitude, $longitude, $datetime);
56+
$response->setContent($data);
57+
} catch (NotAuthorizedException $e) {
58+
$response->setContent($e->getMessage());
59+
} catch (NotFoundException $e) {
60+
$response->setContent($e->getMessage());
61+
}
62+
63+
return $response;
5364
}
5465

5566
/**
@@ -71,9 +82,18 @@ public function getCarbonMonoxideData($latitude, $longitude, $datetime = 'curren
7182
$datetime = 'current';
7283
}
7384
}
85+
86+
$response = new Response();
7487

75-
$data = $this->airPollution->fetchCarbonMonoxideData($latitude, $longitude, $datetime);
88+
try {
89+
$data = $this->airPollution->fetchCarbonMonoxideData($latitude, $longitude, $datetime);
90+
$response->setContent($data);
91+
} catch (NotAuthorizedException $e) {
92+
$response->setContent($e->getMessage());
93+
} catch (NotFoundException $e) {
94+
$response->setContent($e->getMessage());
95+
}
7696

77-
return new Response($data);
97+
return $response;
7898
}
7999
}

Controller/DailyForecastController.php

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Netgen\Bundle\OpenWeatherMapBundle\Controller;
44

55
use Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\DailyForecastInterface;
6+
use Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException;
7+
use Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException;
68
use Symfony\Component\HttpFoundation\Response;
79

810
/**
@@ -37,9 +39,18 @@ public function __construct(DailyForecastInterface $dailyForecast)
3739
*/
3840
public function getForecastByCityName($cityName, $numberOfDays = 16, $countryCode = '')
3941
{
40-
$data = $this->dailyForecast->fetchForecastByCityName($cityName, $countryCode, $numberOfDays);
42+
$response = new Response();
4143

42-
return new Response($data);
44+
try {
45+
$data = $this->dailyForecast->fetchForecastByCityName($cityName, $countryCode, $numberOfDays);
46+
$response->setContent($data);
47+
} catch (NotAuthorizedException $e) {
48+
$response->setContent($e->getMessage());
49+
} catch (NotFoundException $e) {
50+
$response->setContent($e->getMessage());
51+
}
52+
53+
return $response;
4354
}
4455

4556
/**
@@ -52,9 +63,18 @@ public function getForecastByCityName($cityName, $numberOfDays = 16, $countryCod
5263
*/
5364
public function getForecastByCityId($cityId, $numberOfDays = 16)
5465
{
55-
$data = $this->dailyForecast->fetchForecastByCityId($cityId, $numberOfDays);
66+
$response = new Response();
67+
68+
try {
69+
$data = $this->dailyForecast->fetchForecastByCityId($cityId, $numberOfDays);
70+
$response->setContent($data);
71+
} catch (NotAuthorizedException $e) {
72+
$response->setContent($e->getMessage());
73+
} catch (NotFoundException $e) {
74+
$response->setContent($e->getMessage());
75+
}
5676

57-
return new Response($data);
77+
return $response;
5878
}
5979

6080
/**
@@ -68,8 +88,17 @@ public function getForecastByCityId($cityId, $numberOfDays = 16)
6888
*/
6989
public function getForecastByCityGeographicCoordinates($latitude, $longitude, $numberOfDays = 16)
7090
{
71-
$data = $this->dailyForecast->fetchForecastByCityGeographicCoordinates($latitude, $longitude, $numberOfDays);
91+
$response = new Response();
92+
93+
try {
94+
$data = $this->dailyForecast->fetchForecastByCityGeographicCoordinates($latitude, $longitude, $numberOfDays);
95+
$response->setContent($data);
96+
} catch (NotAuthorizedException $e) {
97+
$response->setContent($e->getMessage());
98+
} catch (NotFoundException $e) {
99+
$response->setContent($e->getMessage());
100+
}
72101

73-
return new Response($data);
102+
return $response;
74103
}
75104
}

0 commit comments

Comments
 (0)