Completed
Push — master ( c79f7e...463ede )
by Gallice
02:34
created

Location::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
cc 3
eloc 5
nc 2
nop 2
crap 3
1
<?php
2
3
namespace Tgallice\Wit\Model;
4
5
class Location implements \JsonSerializable
6
{
7
    /**
8
     * @var float
9
     */
10
    private $latitude;
11
12
    /**
13
     * @var float
14
     */
15
    private $longitude;
16
17
    /**
18
     * @param float $latitude
19
     * @param float $longitude
20
     */
21 6
    public function __construct($latitude, $longitude)
22
    {
23 6
        if (empty($latitude) || empty($longitude)) {
24 2
            throw new \InvalidArgumentException('A latitude and longitude must be defined');
25
        }
26
27 4
        $this->latitude = (float) $latitude;
28 4
        $this->longitude = (float) $longitude;
29 4
    }
30
31
    /**
32
     * @return float
33
     */
34 1
    public function getLatitude()
35
    {
36 1
        return $this->latitude;
37
    }
38
39
    /**
40
     * @return float
41
     */
42 1
    public function getLongitude()
43
    {
44 1
        return $this->longitude;
45
    }
46
47
    /**
48
     * @return array
49
     */
50 1
    public function jsonSerialize()
51
    {
52
        return [
53 1
            'latitude' => $this->latitude,
54 1
            'longitude' => $this->longitude,
55 1
        ];
56
    }
57
}
58