Completed
Pull Request — master (#436)
by
unknown
03:50 queued 11s
created

GeoCoordinatesUpdated   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 31.67 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A coordinates() 0 4 1
A serialize() 9 9 1
A deserialize() 10 10 1
A toJsonLd() 0 7 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
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