AirPollution   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A fetchOzoneData() 0 6 1
A fetchCarbonMonoxideData() 0 6 1
A fetchSulfurDioxideData() 0 6 1
A fetchNitrogenDioxideData() 0 6 1
A getResultWithParams() 0 8 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\DateTime;
8
use Marek\OpenWeatherMap\API\Value\Parameter\Input\GeographicCoordinates;
9
use Marek\OpenWeatherMap\API\Value\Response\AirPollution\CarbonMonoxide;
10
use Marek\OpenWeatherMap\API\Value\Response\AirPollution\NitrogenDioxide;
11
use Marek\OpenWeatherMap\API\Value\Response\AirPollution\Ozone;
12
use Marek\OpenWeatherMap\API\Value\Response\AirPollution\SulfurDioxide;
13
use Marek\OpenWeatherMap\API\Weather\Services\AirPollutionInterface;
14
15
class AirPollution extends Base implements AirPollutionInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function fetchOzoneData(GeographicCoordinates $coordinates, DateTime $datetime): Ozone
21
    {
22
        $response = $this->getResultWithParams(self::URL_OZONE, $coordinates, $datetime);
23
24
        return $this->denormalizer->denormalize($response, new Ozone());
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function fetchCarbonMonoxideData(GeographicCoordinates $coordinates, DateTime $datetime): CarbonMonoxide
31
    {
32
        $response = $this->getResultWithParams(self::URL_CARBON_MONOXIDE, $coordinates, $datetime);
33
34
        return $this->denormalizer->denormalize($response, new CarbonMonoxide());
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function fetchSulfurDioxideData(GeographicCoordinates $coordinates, DateTime $datetime): SulfurDioxide
41
    {
42
        $response = $this->getResultWithParams(self::URL_SULFUR_DIOXIDE, $coordinates, $datetime);
43
44
        return $this->denormalizer->denormalize($response, new SulfurDioxide());
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function fetchNitrogenDioxideData(GeographicCoordinates $coordinates, DateTime $datetime): NitrogenDioxide
51
    {
52
        $response = $this->getResultWithParams(self::URL_NITROGEN_DIOXIDE, $coordinates, $datetime);
53
54
        return $this->denormalizer->denormalize($response, new NitrogenDioxide());
55
    }
56
57
    /**
58
     * @param string $url
59
     * @param GeographicCoordinates $coordinates
60
     * @param DateTime $datetime
61
     *
62
     * @return array
63
     */
64
    protected function getResultWithParams($url, GeographicCoordinates $coordinates, DateTime $datetime)
65
    {
66
        $params = $this->factory->buildBag($url);
67
        $params->setUriParameter($coordinates);
68
        $params->setUriParameter($datetime);
69
70
        return $this->getResult($this->factory->build($params));
71
    }
72
}
73