Location   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 20.34 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
c 2
b 0
f 0
lcom 0
cbo 1
dl 12
loc 59
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getLatitude() 0 4 1
A getLongitude() 0 4 1
A __toString() 0 4 1
A __construct() 0 8 1
A assertNumeric() 12 12 4

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
namespace Arthem\GoogleApi\Domain\Place\VO;
4
5
use Arthem\GoogleApi\Domain\Place\Exception\InvalidCoordinateException;
6
7
class Location
8
{
9
    /**
10
     * @var float
11
     */
12
    private $latitude;
13
14
    /**
15
     * @var float
16
     */
17
    private $longitude;
18
19
    /**
20
     * @param float $latitude
21
     * @param float $longitude
22
     */
23
    public function __construct($latitude, $longitude)
24
    {
25
        $this->assertNumeric('latitude', $latitude);
26
        $this->assertNumeric('longitude', $longitude);
27
28
        $this->latitude = (float) $latitude;
29
        $this->longitude = (float) $longitude;
30
    }
31
32 View Code Duplication
    private function assertNumeric($type, $coordinate)
0 ignored issues
show
Duplication introduced by
This method 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...
33
    {
34
        if (!is_float($coordinate) && !is_int($coordinate) && !is_double($coordinate)) {
35
            throw new InvalidCoordinateException(
36
                sprintf(
37
                    'Invalid %s: expected float, int or double, got %s',
38
                    $type,
39
                    gettype($coordinate)
40
                )
41
            );
42
        }
43
    }
44
45
    /**
46
     * @return float
47
     */
48
    public function getLatitude()
49
    {
50
        return $this->latitude;
51
    }
52
53
    /**
54
     * @return float
55
     */
56
    public function getLongitude()
57
    {
58
        return $this->longitude;
59
    }
60
61
    public function __toString()
62
    {
63
        return $this->getLatitude().','.$this->getLongitude();
64
    }
65
}
66