Completed
Push — master ( b3fd52...4771e3 )
by Mario
07:29
created

Weather   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 98
Duplicated Lines 50 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 6
dl 49
loc 98
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A byCityId() 9 9 1
A byGeographicCoordinates() 10 10 1
A byZipCode() 9 9 1
A byCityName() 0 9 1
A withinARectangleZone() 0 10 1
A inCycle() 12 12 1
A severalCityIds() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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)
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...
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)
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...
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)
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...
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)
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...
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)
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...
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