CWByCityId::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
eloc 4
c 2
b 1
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Rawaby88\OpenWeatherMap\Services;
4
5
use Rawaby88\OpenWeatherMap\Interfaces\CWSingleResultInterface;
6
use Rawaby88\OpenWeatherMap\Traits\CWSingleResultTrait;
7
use Rawaby88\OpenWeatherMap\WeatherFactory;
8
9
/**
10
 * Class CWByCityId.
11
 */
12
class CWByCityId extends WeatherFactory implements CWSingleResultInterface
13
{
14
    use CWSingleResultTrait;
15
16
    /**
17
     * @var int City ID. List of city ID 'city.list.json.gz'
18
     */
19
    protected $cityId;
20
21
    /**
22
     * CWByCityName constructor.
23
     *
24
     * You can make an API call by city ID. List of city ID 'city.list.json.gz' can be downloaded
25
     * here http://bulk.openweathermap.org/sample/
26
     *
27
     * @param int $cityId City ID. List of city ID 'city.list.json.gz'
28
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
29
     */
30
    public function __construct(int $cityId)
31
    {
32
        parent::__construct();
33
        $this->apiCall = 'weather';
34
        $this->cityId = $cityId;
35
        $this->params = $this->paramsToArray();
36
    }
37
38
    /**
39
     * Generate query parameters for api call.
40
     * @return array
41
     */
42
    private function paramsToArray(): array
43
    {
44
        return ['id' => $this->cityId];
45
    }
46
}
47