HourForecast::fetchForecastByCityName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Marek\OpenWeatherMap\Core\Weather;
6
7
use Marek\OpenWeatherMap\API\Value\Parameter\Input\CityId;
8
use Marek\OpenWeatherMap\API\Value\Parameter\Input\CityName;
9
use Marek\OpenWeatherMap\API\Value\Parameter\Input\GeographicCoordinates;
10
use Marek\OpenWeatherMap\API\Value\Parameter\Input\ZipCode;
11
use Marek\OpenWeatherMap\API\Value\Response\HourForecast\AggregatedHourForecast;
12
use Marek\OpenWeatherMap\API\Weather\Services\HourForecastInterface;
13
14
class HourForecast extends Base implements HourForecastInterface
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function fetchForecastByCityName(CityName $cityName): AggregatedHourForecast
20
    {
21
        $params = $this->factory->buildBag(self::BASE_URL);
22
        $params->setGetParameter($cityName);
23
24
        $response = $this->getResult($this->factory->build($params));
25
26
        return $this->denormalizer->denormalize($response, new AggregatedHourForecast());
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function fetchForecastByCityId(CityId $cityId): AggregatedHourForecast
33
    {
34
        $params = $this->factory->buildBag(self::BASE_URL);
35
        $params->setGetParameter($cityId);
36
37
        $response = $this->getResult($this->factory->build($params));
38
39
        return $this->denormalizer->denormalize($response, new AggregatedHourForecast());
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function fetchForecastByZipCode(ZipCode $zipCode): AggregatedHourForecast
46
    {
47
        $params = $this->factory->buildBag(self::BASE_URL);
48
        $params->setGetParameter($zipCode);
49
50
        $response = $this->getResult($this->factory->build($params));
51
52
        return $this->denormalizer->denormalize($response, new AggregatedHourForecast());
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 View Code Duplication
    public function fetchForecastByCityGeographicCoordinates(GeographicCoordinates $coordinates): AggregatedHourForecast
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...
59
    {
60
        $params = $this->factory->buildBag(self::BASE_URL);
61
        $params->setGetParameter($coordinates->getLatitude());
62
        $params->setGetParameter($coordinates->getLongitude());
63
64
        $response = $this->getResult($this->factory->build($params));
65
66
        return $this->denormalizer->denormalize($response, new AggregatedHourForecast());
67
    }
68
}
69