HourForecast   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 28.57 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 12
loc 42
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fetchForecastByCityName() 12 12 2
A fetchForecastByCityId() 0 8 1
A fetchForecastByCityGeographicCoordinates() 0 8 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 Netgen\Bundle\OpenWeatherMapBundle\Core;
4
5
use Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\HourForecastInterface;
6
7
/**
8
 * Class HourForecast.
9
 */
10
class HourForecast extends WeatherBase implements HourForecastInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15 View Code Duplication
    public function fetchForecastByCityName($cityName, $countryCode = '')
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...
16
    {
17
        if (empty($countryCode)) {
18
            $queryPart = '/forecast?q=' . $cityName;
19
        } else {
20
            $queryPart = '/forecast?q=' . $cityName . ',' . $countryCode;
21
        }
22
23
        $queryPart = $queryPart . $this->getParams();
24
25
        return $this->getResult(self::BASE_URL, $queryPart);
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function fetchForecastByCityId($cityId)
32
    {
33
        $queryPart = '/forecast?id=' . $cityId;
34
35
        $queryPart = $queryPart . $this->getParams();
36
37
        return $this->getResult(self::BASE_URL, $queryPart);
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function fetchForecastByCityGeographicCoordinates($latitude, $longitude)
44
    {
45
        $queryPart = '/forecast?lat=' . $latitude . '&lon=' . $longitude;
46
47
        $queryPart = $queryPart . $this->getParams();
48
49
        return $this->getResult(self::BASE_URL, $queryPart);
50
    }
51
}
52