Completed
Pull Request — master (#306)
by Luc
07:37
created

TitleTranslated   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

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