Base::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Marek\OpenWeatherMap\Core\Weather;
6
7
use Marek\OpenWeatherMap\API\Cache\HandlerInterface;
8
use Marek\OpenWeatherMap\API\Exception\APIException;
9
use Marek\OpenWeatherMap\API\Exception\ExceptionThrower;
10
use Marek\OpenWeatherMap\Denormalizer\DenormalizerInterface;
11
use Marek\OpenWeatherMap\Factory\UrlFactory;
12
use Marek\OpenWeatherMap\Http\Client\HttpClientInterface;
13
14
abstract class Base
15
{
16
    /**
17
     * @var HttpClientInterface
18
     */
19
    protected $client;
20
21
    /**
22
     * @var UrlFactory
23
     */
24
    protected $factory;
25
26
    /**
27
     * @var HandlerInterface
28
     */
29
    protected $handler;
30
31
    /**
32
     * @var \Marek\OpenWeatherMap\Denormalizer\DenormalizerInterface
33
     */
34
    protected $denormalizer;
35
36
    /**
37
     * Base constructor.
38
     *
39
     * @param HttpClientInterface $client
40
     * @param UrlFactory $factory
41
     * @param HandlerInterface $handler
42
     * @param \Marek\OpenWeatherMap\Denormalizer\DenormalizerInterface $hydrator
0 ignored issues
show
Bug introduced by
There is no parameter named $hydrator. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
43
     */
44
    public function __construct(HttpClientInterface $client, UrlFactory $factory, HandlerInterface $handler, DenormalizerInterface $denormalizer)
45
    {
46
        $this->client = $client;
47
        $this->factory = $factory;
48
        $this->handler = $handler;
49
        $this->denormalizer = $denormalizer;
50
    }
51
52
    /**
53
     * @param string $url
54
     *
55
     * @throws APIException
56
     *
57
     * @return array
58
     */
59
    protected function getResult(string $url): array
60
    {
61
        if ($this->handler->has($url)) {
62
            return $this->handler->get($url);
63
        }
64
65
        $response = $this->client->get($url);
66
67
        ExceptionThrower::throwException($response->getStatusCode(), $response->getMessage());
68
69
        return $response->getData();
70
    }
71
}
72