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

Latitude   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 49
loc 49
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A getLatitude() 4 4 1
A getGetParameterValue() 4 4 1
A getGetParameterName() 4 4 1
A validate() 6 6 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 Latitude 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 $latitude;
16
17
    /**
18
     * Latitude constructor.
19
     *
20
     * @param float $latitude
21
     */
22
    public function __construct(float $latitude)
23
    {
24
        $this->validate($latitude);
25
        $this->latitude = $latitude;
26
    }
27
28
    /**
29
     * @return float
30
     */
31
    public function getLatitude()
32
    {
33
        return $this->latitude;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getGetParameterValue()
40
    {
41
        return (string) $this->latitude;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function getGetParameterName()
48
    {
49
        return 'lat';
50
    }
51
52
    protected function validate(float $latitude): void
53
    {
54
        if ($latitude < -90 || $latitude > 90) {
55
            throw new InvalidArgumentException((string)$latitude, 'latitude', self::class);
56
        }
57
    }
58
}
59