GeoCoordinatesUpdated::serialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CultuurNet\UDB3\Organizer\Events;
6
7
use CultuurNet\Geocoding\Coordinate\Coordinates;
8
use CultuurNet\Geocoding\Coordinate\Latitude;
9
use CultuurNet\Geocoding\Coordinate\Longitude;
10
11 View Code Duplication
final class GeoCoordinatesUpdated extends OrganizerEvent
0 ignored issues
show
Duplication introduced by
This class 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...
12
{
13
    /**
14
     * @var Coordinates
15
     */
16
    private $coordinates;
17
18
    public function __construct(string $organizerId, Coordinates $coordinates)
19
    {
20
        parent::__construct($organizerId);
21
        $this->coordinates = $coordinates;
22
    }
23
24
    public function coordinates(): Coordinates
25
    {
26
        return $this->coordinates;
27
    }
28
29
    public function serialize(): array
30
    {
31
        return parent::serialize() + [
32
            'coordinates' => [
33
                'lat' => $this->coordinates->getLatitude()->toDouble(),
34
                'long' => $this->coordinates->getLongitude()->toDouble(),
35
            ],
36
        ];
37
    }
38
39
    public static function deserialize(array $data): GeoCoordinatesUpdated
40
    {
41
        return new static(
42
            $data['organizer_id'],
43
            new Coordinates(
44
                new Latitude($data['coordinates']['lat']),
45
                new Longitude($data['coordinates']['long'])
46
            )
47
        );
48
    }
49
}
50