Completed
Pull Request — master (#290)
by Luc
04:33
created

UrlUpdated   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A getUrl() 4 4 1
A serialize() 6 6 1
A deserialize() 7 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
2
3
namespace CultuurNet\UDB3\Organizer\Events;
4
5
use ValueObjects\Web\Url;
6
7 View Code Duplication
class UrlUpdated 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...
8
{
9
    /**
10
     * @var Url
11
     */
12
    private $url;
13
14
    /**
15
     * UrlUpdated constructor.
16
     * @param string $organizerId
17
     * @param Url $url
18
     */
19
    public function __construct(
20
        $organizerId,
21
        Url $url
22
    ) {
23
        parent::__construct($organizerId);
24
        $this->url = $url;
25
    }
26
27
    /**
28
     * @return Url
29
     */
30
    public function getUrl()
31
    {
32
        return $this->url;
33
    }
34
35
    /**
36
     * @return array
37
     */
38
    public function serialize()
39
    {
40
        return parent::serialize() + [
41
                'url' => (string) $this->getUrl()
42
            ];
43
    }
44
45
    /**
46
     * @param array $data
47
     * @return static
48
     */
49
    public static function deserialize(array $data)
50
    {
51
        return new static(
52
            $data['organizer_id'],
53
            Url::fromNative($data['url'])
54
        );
55
    }
56
}
57