1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Marek\OpenWeatherMap\Core\Weather; |
4
|
|
|
|
5
|
|
|
use Marek\OpenWeatherMap\API\Value\Parameter\Input\BoundingBox; |
6
|
|
|
use Marek\OpenWeatherMap\API\Value\Parameter\Input\CityCount; |
7
|
|
|
use Marek\OpenWeatherMap\API\Value\Parameter\Input\CityId; |
8
|
|
|
use Marek\OpenWeatherMap\API\Value\Parameter\Input\CityIds; |
9
|
|
|
use Marek\OpenWeatherMap\API\Value\Parameter\Input\CityName; |
10
|
|
|
use Marek\OpenWeatherMap\API\Value\Parameter\Input\Cluster; |
11
|
|
|
use Marek\OpenWeatherMap\API\Value\Parameter\Input\Latitude; |
12
|
|
|
use Marek\OpenWeatherMap\API\Value\Parameter\Input\Longitude; |
13
|
|
|
use Marek\OpenWeatherMap\API\Value\Parameter\Input\ZipCode; |
14
|
|
|
use Marek\OpenWeatherMap\API\Value\Response\Weather\AggregatedWeather; |
15
|
|
|
use Marek\OpenWeatherMap\API\Weather\Services\WeatherInterface; |
16
|
|
|
use Marek\OpenWeatherMap\API\Value\Response\Weather\Weather as WeatherResponse; |
17
|
|
|
|
18
|
|
|
class Weather extends Base implements WeatherInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @inheritDoc |
22
|
|
|
*/ |
23
|
|
|
public function byCityName(CityName $cityName) |
24
|
|
|
{ |
25
|
|
|
$params = $this->factory->buildBag(self::URL_WEATHER); |
26
|
|
|
$params->setParameter($cityName); |
27
|
|
|
|
28
|
|
|
$response = $this->getResult($this->factory->build($params)); |
29
|
|
|
|
30
|
|
|
return $this->hydrator->hydrate($response, new WeatherResponse()); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @inheritDoc |
35
|
|
|
*/ |
36
|
|
View Code Duplication |
public function byCityId(CityId $cityId) |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$params = $this->factory->buildBag(self::URL_WEATHER); |
39
|
|
|
$params->setParameter($cityId); |
40
|
|
|
|
41
|
|
|
$response = $this->getResult($this->factory->build($params)); |
42
|
|
|
|
43
|
|
|
return $this->hydrator->hydrate($response, new WeatherResponse()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @inheritDoc |
48
|
|
|
*/ |
49
|
|
View Code Duplication |
public function byGeographicCoordinates(Latitude $latitude, Longitude $longitude) |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
$params = $this->factory->buildBag(self::URL_WEATHER); |
52
|
|
|
$params->setParameter($latitude); |
53
|
|
|
$params->setParameter($longitude); |
54
|
|
|
|
55
|
|
|
$response = $this->getResult($this->factory->build($params)); |
56
|
|
|
|
57
|
|
|
return $this->hydrator->hydrate($response, new WeatherResponse()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @inheritDoc |
62
|
|
|
*/ |
63
|
|
View Code Duplication |
public function byZipCode(ZipCode $zipCode) |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
$params = $this->factory->buildBag(self::URL_WEATHER); |
66
|
|
|
$params->setParameter($zipCode); |
67
|
|
|
|
68
|
|
|
$response = $this->getResult($this->factory->build($params)); |
69
|
|
|
|
70
|
|
|
return $this->hydrator->hydrate($response, new WeatherResponse()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @inheritDoc |
75
|
|
|
*/ |
76
|
|
|
public function withinARectangleZone(BoundingBox $bbox, Cluster $cluster) |
77
|
|
|
{ |
78
|
|
|
$params = $this->factory->buildBag(self::URL_BBOX); |
79
|
|
|
$params->setParameter($bbox); |
80
|
|
|
$params->setParameter($cluster); |
81
|
|
|
|
82
|
|
|
$response = $this->getResult($this->factory->build($params)); |
83
|
|
|
|
84
|
|
|
return $this->hydrator->hydrate($response, new AggregatedWeather()); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @inheritDoc |
89
|
|
|
*/ |
90
|
|
View Code Duplication |
public function inCycle(Latitude $latitude, Longitude $longitude, Cluster $cluster, CityCount $cnt) |
|
|
|
|
91
|
|
|
{ |
92
|
|
|
$params = $this->factory->buildBag(self::URL_CYCLE); |
93
|
|
|
$params->setParameter($latitude); |
94
|
|
|
$params->setParameter($longitude); |
95
|
|
|
$params->setParameter($cluster); |
96
|
|
|
$params->setParameter($cnt); |
97
|
|
|
|
98
|
|
|
$response = $this->getResult($this->factory->build($params)); |
99
|
|
|
|
100
|
|
|
return $this->hydrator->hydrate($response, new AggregatedWeather()); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @inheritDoc |
105
|
|
|
*/ |
106
|
|
View Code Duplication |
public function severalCityIds(CityIds $cityIds) |
|
|
|
|
107
|
|
|
{ |
108
|
|
|
$params = $this->factory->buildBag(self::URL_CITIES); |
109
|
|
|
$params->setParameter($cityIds); |
110
|
|
|
|
111
|
|
|
$response = $this->getResult($this->factory->build($params)); |
112
|
|
|
|
113
|
|
|
return $this->hydrator->hydrate($response, new AggregatedWeather()); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.