Completed
Pull Request — master (#436)
by
unknown
02:56
created

GeoCoordinatesUpdated   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 49
loc 49
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A coordinates() 4 4 1
A serialize() 9 9 1
A deserialize() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
9 View Code Duplication
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...
10
{
11
    /**
12
     * @var Coordinates
13
     */
14
    private $coordinates;
15
16
    public function __construct(string $organizerId, Coordinates $coordinates)
17
    {
18
        parent::__construct($organizerId);
19
        $this->coordinates = $coordinates;
20
    }
21
22
    /**
23
     * @return Coordinates
24
     */
25
    public function coordinates(): Coordinates
26
    {
27
        return $this->coordinates;
28
    }
29
30
    /**
31
     * @return array
32
     */
33
    public function serialize()
34
    {
35
        return parent::serialize() + [
36
                'coordinates' => [
37
                    'lat' => $this->coordinates->getLatitude()->toDouble(),
38
                    'long' => $this->coordinates->getLongitude()->toDouble(),
39
                ],
40
            ];
41
    }
42
43
    /**
44
     * @param array $data
45
     * @return static
46
     */
47
    public static function deserialize(array $data)
48
    {
49
        return new static(
50
            $data['item_id'],
51
            new Coordinates(
52
                new Latitude($data['coordinates']['lat']),
53
                new Longitude($data['coordinates']['long'])
54
            )
55
        );
56
    }
57
}
58