Completed
Push — master ( 6551be...435af8 )
by Mario
09:41
created

UltravioletIndex   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 28.21 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
dl 11
loc 39
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fetchCurrentUltravioletIndex() 0 10 1
A fetchForecastUltravioletIndex() 11 11 1
A fetchHistoricalUltravioletIndex() 0 13 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
declare(strict_types=1);
4
5
namespace Marek\OpenWeatherMap\Core\Weather;
6
7
use Marek\OpenWeatherMap\API\Value\Parameter\Input\DaysCount;
8
use Marek\OpenWeatherMap\API\Value\Parameter\Input\GeographicCoordinates;
9
use Marek\OpenWeatherMap\API\Value\Parameter\Input\Period;
10
use Marek\OpenWeatherMap\API\Value\Response\UltravioletIndex\AggregatedUltravioletIndex;
11
use Marek\OpenWeatherMap\API\Value\Response\UltravioletIndex\UltravioletIndex as UltravioletIndexResponse;
12
use Marek\OpenWeatherMap\API\Weather\Services\UltravioletIndexInterface;
13
14
final class UltravioletIndex extends Base implements UltravioletIndexInterface
15
{
16
    public function fetchCurrentUltravioletIndex(GeographicCoordinates $coordinates): UltravioletIndexResponse
17
    {
18
        $params = $this->factory->buildBag(self::BASE_URL);
19
        $params->setGetParameter($coordinates->getLatitude());
20
        $params->setGetParameter($coordinates->getLongitude());
21
22
        $result = $this->getResult($this->factory->build($params));
23
24
        return $this->denormalizer->denormalize($result, new UltravioletIndexResponse());
25
    }
26
27 View Code Duplication
    public function fetchForecastUltravioletIndex(GeographicCoordinates $coordinates, DaysCount $daysCount): AggregatedUltravioletIndex
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...
28
    {
29
        $params = $this->factory->buildBag(self::BASE_URL . '/forecast');
30
        $params->setGetParameter($coordinates->getLatitude());
31
        $params->setGetParameter($coordinates->getLongitude());
32
        $params->setGetParameter($daysCount);
33
34
        $result = $this->getResult($this->factory->build($params));
35
36
        return $this->denormalizer->denormalize($result, new AggregatedUltravioletIndex());
37
    }
38
39
    public function fetchHistoricalUltravioletIndex(GeographicCoordinates $coordinates, Period $period, DaysCount $daysCount): AggregatedUltravioletIndex
40
    {
41
        $params = $this->factory->buildBag(self::BASE_URL . '/history');
42
        $params->setGetParameter($coordinates->getLatitude());
43
        $params->setGetParameter($coordinates->getLongitude());
44
        $params->setGetParameter($period->getStart());
45
        $params->setGetParameter($period->getEnd());
46
        $params->setGetParameter($daysCount);
47
48
        $result = $this->getResult($this->factory->build($params));
49
50
        return $this->denormalizer->denormalize($result, new AggregatedUltravioletIndex());
51
    }
52
}
53