Location::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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