Longitude::getGetParameterName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 4
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Marek\OpenWeatherMap\API\Value\Parameter\Input;
6
7
use Marek\OpenWeatherMap\API\Exception\InvalidArgumentException;
8
use Marek\OpenWeatherMap\API\Value\Parameter\GetParameterInterface;
9
10 View Code Duplication
class Longitude implements GetParameterInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
{
12
    /**
13
     * @var float
14
     */
15
    protected $longitude;
16
17
    /**
18
     * Longitude constructor.
19
     *
20
     *
21
     * @param float $longitude
22
     *
23
     * @throws \Marek\OpenWeatherMap\API\Exception\InvalidArgumentException
24
     */
25
    public function __construct(float $longitude)
26
    {
27
        $this->validate($longitude);
28
        $this->longitude = $longitude;
29
    }
30
31
    /**
32
     * @return float
33
     */
34
    public function getLongitude(): float
35
    {
36
        return $this->longitude;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getGetParameterValue(): string
43
    {
44
        return (string) $this->longitude;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getGetParameterName(): string
51
    {
52
        return 'lon';
53
    }
54
55
    /**
56
     * @param float $longitude
57
     *
58
     * @throws \Marek\OpenWeatherMap\API\Exception\InvalidArgumentException
59
     */
60
    protected function validate(float $longitude): void
61
    {
62
        if ($longitude < -180 || $longitude > 180) {
63
            throw new InvalidArgumentException((string) $longitude, 'longitude', self::class);
64
        }
65
    }
66
}
67