Completed
Push — master ( 08753a...42665f )
by Sascha-Oliver
05:38
created

TranslationUpdated   B

Complexity

Total Complexity 40

Size/Duplication

Total Lines 231
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 40
lcom 1
cbo 3
dl 231
loc 231
ccs 0
cts 137
cp 0
rs 8.2608
c 0
b 0
f 0

25 Methods

Rating   Name   Duplication   Size   Complexity  
F createFromArray() 43 43 16
A getId() 4 4 1
A setId() 4 4 1
A getContent() 4 4 1
A setContent() 4 4 1
A isUnverified() 4 4 1
A setUnverified() 4 4 1
A isExcluded() 4 4 1
A setExcluded() 4 4 1
A getPluralSuffix() 4 4 1
A setPluralSuffix() 4 4 1
A getKey() 4 4 1
A setKey() 4 4 1
A getCreatedAt() 4 4 1
A setCreatedAt() 4 4 1
A getUpdatedAt() 4 4 1
A setUpdatedAt() 4 4 1
A getWordCount() 4 4 1
A setWordCount() 4 4 1
A getPlaceholders() 4 4 1
A setPlaceholders() 4 4 1
A getLocale() 4 4 1
A setLocale() 4 4 1
A getUser() 4 4 1
A setUser() 4 4 1

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like TranslationUpdated often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use TranslationUpdated, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license.  See the LICENSE file for details.
8
 */
9
10
namespace FAPI\PhraseApp\Model\Translation;
11
12
use FAPI\PhraseApp\Model\CreatableFromArray;
13
14
/**
15
 * @author Sascha-Oliver Prolic <[email protected]>
16
 */
17 View Code Duplication
class TranslationUpdated implements CreatableFromArray
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...
18
{
19
    /**
20
     * @var string
21
     */
22
    private $id;
23
24
    /**
25
     * @var string
26
     */
27
    private $content;
28
29
    /**
30
     * @var bool
31
     */
32
    private $unverified;
33
34
    /**
35
     * @var bool
36
     */
37
    private $excluded;
38
39
    /**
40
     * @var string
41
     */
42
    private $pluralSuffix;
43
44
    /**
45
     * @var string
46
     */
47
    private $createdAt;
48
49
    /**
50
     * @var string
51
     */
52
    private $updatedAt;
53
54
    /**
55
     * @var array
56
     */
57
    private $placeholders = [];
58
59
    /**
60
     * @var int
61
     */
62
    private $wordCount;
63
64
    /**
65
     * @var Key
66
     */
67
    private $key;
68
69
    /**
70
     * @var Locale
71
     */
72
    private $locale;
73
74
    /**
75
     * @var User
76
     */
77
    private $user;
78
79
    /**
80
     * @param array $data
81
     *
82
     * @return TranslationUpdated
83
     */
84
    public static function createFromArray(array $data)
85
    {
86
        $self = new self();
87
88
        if (isset($data['id'])) {
89
            $self->setId($data['id']);
90
        }
91
        if (isset($data['content'])) {
92
            $self->setContent($data['content']);
93
        }
94
        if (isset($data['unverified'])) {
95
            $self->setUnverified($data['unverified']);
96
        }
97
        if (isset($data['excluded'])) {
98
            $self->setExcluded($data['excluded']);
99
        }
100
        if (isset($data['plural_suffix'])) {
101
            $self->setPluralSuffix($data['plural_suffix']);
102
        }
103
        if (isset($data['created_at'])) {
104
            $self->setCreatedAt($data['created_at']);
105
        }
106
        if (isset($data['updated_at'])) {
107
            $self->setUpdatedAt($data['updated_at']);
108
        }
109
        if (isset($data['placeholders'])) {
110
            $self->setPlaceholders($data['placeholders']);
111
        }
112
        if (isset($data['word_count'])) {
113
            $self->setWordCount($data['word_count']);
114
        }
115
        if (isset($data['key']) && is_array($data['key'])) {
116
            $self->setKey(Key::createFromArray($data['key']));
117
        }
118
        if (isset($data['locale']) && is_array($data['locale'])) {
119
            $self->setLocale(Locale::createFromArray($data['locale']));
120
        }
121
        if (isset($data['user']) && is_array($data['user'])) {
122
            $self->setUser(User::createFromArray($data['user']));
123
        }
124
125
        return $self;
126
    }
127
128
    public function getId(): string
129
    {
130
        return $this->id;
131
    }
132
133
    private function setId(string $id)
134
    {
135
        $this->id = $id;
136
    }
137
138
    public function getContent(): string
139
    {
140
        return $this->content;
141
    }
142
143
    private function setContent(string $content)
144
    {
145
        $this->content = $content;
146
    }
147
148
    public function isUnverified(): bool
149
    {
150
        return $this->unverified;
151
    }
152
153
    private function setUnverified(bool $unverified)
154
    {
155
        $this->unverified = $unverified;
156
    }
157
158
    public function isExcluded(): bool
159
    {
160
        return $this->excluded;
161
    }
162
163
    private function setExcluded(bool $excluded)
164
    {
165
        $this->excluded = $excluded;
166
    }
167
168
    public function getPluralSuffix(): string
169
    {
170
        return $this->pluralSuffix;
171
    }
172
173
    private function setPluralSuffix(string $pluralSuffix)
174
    {
175
        $this->pluralSuffix = $pluralSuffix;
176
    }
177
178
    public function getKey(): Key
179
    {
180
        return $this->key;
181
    }
182
183
    private function setKey(Key $key)
184
    {
185
        $this->key = $key;
186
    }
187
188
    public function getCreatedAt(): string
189
    {
190
        return $this->createdAt;
191
    }
192
193
    private function setCreatedAt(string $createdAt)
194
    {
195
        $this->createdAt = $createdAt;
196
    }
197
198
    public function getUpdatedAt(): string
199
    {
200
        return $this->updatedAt;
201
    }
202
203
    private function setUpdatedAt(string $updatedAt)
204
    {
205
        $this->updatedAt = $updatedAt;
206
    }
207
208
    public function getWordCount(): int
209
    {
210
        return $this->wordCount;
211
    }
212
213
    private function setWordCount(int $wordCount)
214
    {
215
        $this->wordCount = $wordCount;
216
    }
217
218
    public function getPlaceholders(): array
219
    {
220
        return $this->placeholders;
221
    }
222
223
    private function setPlaceholders(array $placeholders)
224
    {
225
        $this->placeholders = $placeholders;
226
    }
227
228
    public function getLocale(): Locale
229
    {
230
        return $this->locale;
231
    }
232
233
    private function setLocale(Locale $locale)
234
    {
235
        $this->locale = $locale;
236
    }
237
238
    public function getUser(): User
239
    {
240
        return $this->user;
241
    }
242
243
    private function setUser(User $user)
244
    {
245
        $this->user = $user;
246
    }
247
}
248