Completed
Push — master ( 922541...c48d97 )
by Mario
06:18
created

Longitude::validate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 1
dl 6
loc 6
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
     * @param float $longitude
21
     */
22
    public function __construct(float $longitude)
23
    {
24
        $this->validate($longitude);
25
        $this->longitude = $longitude;
26
    }
27
28
    /**
29
     * @return float
30
     */
31
    public function getLongitude()
32
    {
33
        return $this->longitude;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getGetParameterValue()
40
    {
41
        return (string) $this->longitude;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function getGetParameterName()
48
    {
49
        return 'lon';
50
    }
51
52
    protected function validate(float $longitude): void
53
    {
54
        if ($longitude < -180 || $longitude > 180) {
55
            throw new InvalidArgumentException((string)$longitude, 'longitude', self::class);
56
        }
57
    }
58
}
59