Completed
Pull Request — master (#436)
by
unknown
03:00
created

GeoCoordinatesUpdated::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php declare(strict_types=1);
2
3
namespace CultuurNet\UDB3\Organizer\Events;
4
5
use CultuurNet\Geocoding\Coordinate\Coordinates;
6
use CultuurNet\Geocoding\Coordinate\Latitude;
7
use CultuurNet\Geocoding\Coordinate\Longitude;
8
use CultuurNet\UDB3\JsonLdSerializableInterface;
9
10
class GeoCoordinatesUpdated extends OrganizerEvent implements JsonLdSerializableInterface
11
{
12
    /**
13
     * @var Coordinates
14
     */
15
    private $coordinates;
16
17
    public function __construct(string $organizerId, Coordinates $coordinates)
18
    {
19
        parent::__construct($organizerId);
20
        $this->coordinates = $coordinates;
21
    }
22
23
    /**
24
     * @return Coordinates
25
     */
26
    public function coordinates(): Coordinates
27
    {
28
        return $this->coordinates;
29
    }
30
31
    /**
32
     * @return array
33
     */
34 View Code Duplication
    public function serialize()
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...
35
    {
36
        return parent::serialize() + [
37
                'coordinates' => [
38
                    'lat' => $this->coordinates->getLatitude()->toDouble(),
39
                    'long' => $this->coordinates->getLongitude()->toDouble(),
40
                ],
41
            ];
42
    }
43
44
    /**
45
     * @param array $data
46
     * @return static
47
     */
48 View Code Duplication
    public static function deserialize(array $data)
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...
49
    {
50
        return new static(
51
            $data['item_id'],
52
            new Coordinates(
53
                new Latitude($data['coordinates']['lat']),
54
                new Longitude($data['coordinates']['long'])
55
            )
56
        );
57
    }
58
59
    /**
60
     * Convert the object to json ld.
61
     */
62
    public function toJsonLd()
63
    {
64
        return [
65
            'latitude' => $this->coordinates->getLatitude()->toDouble(),
66
            'longitude' => $this->coordinates->getLongitude()->toDouble(),
67
        ];
68
    }
69
}
70