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