Weather::inCycle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Marek\OpenWeatherMap\Core\Weather;
6
7
use Marek\OpenWeatherMap\API\Value\Parameter\Input\BoundingBox;
8
use Marek\OpenWeatherMap\API\Value\Parameter\Input\CityCount;
9
use Marek\OpenWeatherMap\API\Value\Parameter\Input\CityId;
10
use Marek\OpenWeatherMap\API\Value\Parameter\Input\CityIds;
11
use Marek\OpenWeatherMap\API\Value\Parameter\Input\CityName;
12
use Marek\OpenWeatherMap\API\Value\Parameter\Input\Cluster;
13
use Marek\OpenWeatherMap\API\Value\Parameter\Input\GeographicCoordinates;
14
use Marek\OpenWeatherMap\API\Value\Parameter\Input\ZipCode;
15
use Marek\OpenWeatherMap\API\Value\Response\Weather\AggregatedWeather;
16
use Marek\OpenWeatherMap\API\Value\Response\Weather\Weather as WeatherResponse;
17
use Marek\OpenWeatherMap\API\Weather\Services\WeatherInterface;
18
19
class Weather extends Base implements WeatherInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function byCityName(CityName $cityName): WeatherResponse
25
    {
26
        $params = $this->factory->buildBag(self::URL_WEATHER);
27
        $params->setGetParameter($cityName);
28
29
        $response = $this->getResult($this->factory->build($params));
30
31
        return $this->denormalizer->denormalize($response, new WeatherResponse());
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function byCityId(CityId $cityId): WeatherResponse
38
    {
39
        $params = $this->factory->buildBag(self::URL_WEATHER);
40
        $params->setGetParameter($cityId);
41
42
        $response = $this->getResult($this->factory->build($params));
43
44
        return $this->denormalizer->denormalize($response, new WeatherResponse());
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 View Code Duplication
    public function byGeographicCoordinates(GeographicCoordinates $coordinates): WeatherResponse
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
51
    {
52
        $params = $this->factory->buildBag(self::URL_WEATHER);
53
        $params->setGetParameter($coordinates->getLatitude());
54
        $params->setGetParameter($coordinates->getLongitude());
55
56
        $response = $this->getResult($this->factory->build($params));
57
58
        return $this->denormalizer->denormalize($response, new WeatherResponse());
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function byZipCode(ZipCode $zipCode): WeatherResponse
65
    {
66
        $params = $this->factory->buildBag(self::URL_WEATHER);
67
        $params->setGetParameter($zipCode);
68
69
        $response = $this->getResult($this->factory->build($params));
70
71
        return $this->denormalizer->denormalize($response, new WeatherResponse());
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function withinARectangleZone(BoundingBox $bbox, Cluster $cluster): AggregatedWeather
78
    {
79
        $params = $this->factory->buildBag(self::URL_BBOX);
80
        $params->setGetParameter($bbox);
81
        $params->setGetParameter($cluster);
82
83
        $response = $this->getResult($this->factory->build($params));
84
85
        return $this->denormalizer->denormalize($response, new AggregatedWeather());
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91 View Code Duplication
    public function inCycle(GeographicCoordinates $coordinates, Cluster $cluster, CityCount $cnt): AggregatedWeather
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
92
    {
93
        $params = $this->factory->buildBag(self::URL_CYCLE);
94
        $params->setGetParameter($coordinates->getLatitude());
95
        $params->setGetParameter($coordinates->getLongitude());
96
        $params->setGetParameter($cluster);
97
        $params->setGetParameter($cnt);
98
99
        $response = $this->getResult($this->factory->build($params));
100
101
        return $this->denormalizer->denormalize($response, new AggregatedWeather());
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107
    public function severalCityIds(CityIds $cityIds): AggregatedWeather
108
    {
109
        $params = $this->factory->buildBag(self::URL_CITIES);
110
        $params->setGetParameter($cityIds);
111
112
        $response = $this->getResult($this->factory->build($params));
113
114
        return $this->denormalizer->denormalize($response, new AggregatedWeather());
115
    }
116
}
117