CWByZipCode   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 13
c 2
b 1
f 0
dl 0
loc 45
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A paramsToArray() 0 8 2
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 CWByZipCode.
11
 */
12
class CWByZipCode extends WeatherFactory implements CWSingleResultInterface
13
{
14
    use CWSingleResultTrait;
15
16
    /**
17
     * @var string Zip code.
18
     */
19
    protected $zipCode;
20
21
    /**
22
     * @var string ISO 3166 country codes.
23
     */
24
    protected $countryCode;
25
26
    /**
27
     * CWByZipCode constructor.
28
     *
29
     * You can call by zip code.
30
     * Please note if countryCode is not specified then the search works for USA as a default.
31
     *
32
     * @param string $zipCode Zip code.
33
     * @param string|null $countryCode ISO 3166 country codes.
34
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
35
     */
36
    public function __construct(string $zipCode, string $countryCode = 'us')
37
    {
38
        parent::__construct();
39
        $this->apiCall = 'weather';
40
        $this->zipCode = $zipCode;
41
        $this->countryCode = $countryCode;
42
        $this->params = $this->paramsToArray();
43
    }
44
45
    /**
46
     * Generate query parameters for api call.
47
     * @return array
48
     */
49
    private function paramsToArray(): array
50
    {
51
        $zip = $this->zipCode;
52
        if ($this->countryCode) {
53
            $zip .= ','.$this->countryCode;
54
        }
55
56
        return ['zip' => $zip];
57
    }
58
}
59