Completed
Pull Request — master (#285)
by Luc
04:48
created

GeoCoordinatesUpdated::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace CultuurNet\UDB3\Place\Events;
4
5
use CultuurNet\Geocoding\Coordinate\Coordinates;
6
use CultuurNet\Geocoding\Coordinate\Latitude;
7
use CultuurNet\Geocoding\Coordinate\Longitude;
8
use CultuurNet\UDB3\Place\PlaceEvent;
9
10
class GeoCoordinatesUpdated extends PlaceEvent
11
{
12
    /**
13
     * @var Coordinates
14
     */
15
    private $coordinates;
16
17
    /**
18
     * @param string $itemId
19
     * @param Coordinates $coordinates
20
     */
21
    public function __construct($itemId, Coordinates $coordinates)
22
    {
23
        parent::__construct($itemId);
24
        $this->coordinates = $coordinates;
25
    }
26
27
    /**
28
     * @return Coordinates
29
     */
30
    public function getCoordinates()
31
    {
32
        return $this->coordinates;
33
    }
34
35
    /**
36
     * @return array
37
     */
38
    public function serialize()
39
    {
40
        return parent::serialize() + [
41
            'coordinates' => [
42
                'lat' => $this->coordinates->getLatitude()->toDouble(),
43
                'long' => $this->coordinates->getLongitude()->toDouble(),
44
            ],
45
        ];
46
    }
47
48
    /**
49
     * @param array $data
50
     * @return GeoCoordinatesUpdated
51
     */
52
    public static function deserialize(array $data)
53
    {
54
        return new GeoCoordinatesUpdated(
55
            $data['place_id'],
56
            new Coordinates(
57
                new Latitude($data['coordinates']['lat']),
58
                new Longitude($data['coordinates']['long'])
59
            )
60
        );
61
    }
62
}
63