AbstractCategoryMessage   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 87
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getParentRootId() 4 4 1
A setParentRootId() 4 4 1
A isEnabled() 4 4 1
A setEnabled() 4 4 1
A getTranslations() 4 4 1
A addTranslation() 4 4 1
A removeTranslation() 4 4 1
A build() 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
declare(strict_types=1);
3
4
namespace Yproximite\Api\Message\Article;
5
6
use Yproximite\Api\Util\Helper;
7
use Yproximite\Api\Message\MessageInterface;
8
use Yproximite\Api\Message\SiteAwareMessageTrait;
9
10
/**
11
 * Class AbstractCategoryMessage
12
 */
13 View Code Duplication
abstract class AbstractCategoryMessage implements MessageInterface
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...
14
{
15
    use SiteAwareMessageTrait;
16
17
    /**
18
     * @var int|null
19
     */
20
    private $parentRootId;
21
22
    /**
23
     * @var bool|null
24
     */
25
    private $enabled;
26
27
    /**
28
     * @var CategoryTranslationMessage[]
29
     */
30
    private $translations = [];
31
32
    /**
33
     * @return int|null
34
     */
35
    public function getParentRootId()
36
    {
37
        return $this->parentRootId;
38
    }
39
40
    /**
41
     * @param int|null $parentRootId
42
     */
43
    public function setParentRootId(int $parentRootId = null)
44
    {
45
        $this->parentRootId = $parentRootId;
46
    }
47
48
    /**
49
     * @return bool|null
50
     */
51
    public function isEnabled()
52
    {
53
        return $this->enabled;
54
    }
55
56
    /**
57
     * @param bool|null $enabled
58
     */
59
    public function setEnabled(bool $enabled = null)
60
    {
61
        $this->enabled = $enabled;
62
    }
63
64
    /**
65
     * @return CategoryTranslationMessage[]
66
     */
67
    public function getTranslations(): array
68
    {
69
        return $this->translations;
70
    }
71
72
    /**
73
     * @param CategoryTranslationMessage $translation
74
     */
75
    public function addTranslation(CategoryTranslationMessage $translation)
76
    {
77
        $this->translations[] = $translation;
78
    }
79
80
    /**
81
     * @param CategoryTranslationMessage $translation
82
     */
83
    public function removeTranslation(CategoryTranslationMessage $translation)
84
    {
85
        array_splice($this->translations, array_search($translation, $this->translations), 1);
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function build()
92
    {
93
        return [
94
            'parentRootId' => $this->getParentRootId(),
95
            'enabled'      => $this->isEnabled(),
96
            'translations' => Helper::buildMessages($this->getTranslations(), 'locale'),
97
        ];
98
    }
99
}
100