CityName::getGetParameterName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Marek\OpenWeatherMap\API\Value\Parameter\Input;
6
7
use Marek\OpenWeatherMap\API\Value\Parameter\GetParameterInterface;
8
9
class CityName implements GetParameterInterface
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $name;
15
16
    /**
17
     * @var string|null
18
     */
19
    protected $code;
20
21
    /**
22
     * CityName constructor.
23
     *
24
     * @param string $name
25
     * @param string|null $code
26
     */
27
    public function __construct(string $name, ?string $code = null)
28
    {
29
        $this->name = $name;
30
        $this->code = $code;
31
    }
32
33
    /**
34
     * @return string
35
     */
36
    public function getName(): string
37
    {
38
        return $this->name;
39
    }
40
41
    /**
42
     * @return string|null
43
     */
44
    public function getCode(): ?string
45
    {
46
        return $this->code;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getGetParameterValue(): string
53
    {
54
        if (null === $this->code) {
55
            return $this->name;
56
        }
57
58
        return $this->name . ',' . (string) $this->code;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function getGetParameterName(): string
65
    {
66
        return 'q';
67
    }
68
}
69