Completed
Push — master ( 5c6dda...f1d038 )
by Tobias
03:08
created

Asset::createFromArray()   F

Complexity

Conditions 12
Paths 2048

Size

Total Lines 40
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 156

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 0
cts 38
cp 0
rs 2.7855
c 0
b 0
f 0
cc 12
eloc 25
nc 2048
nop 1
crap 156

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace FAPI\Localise\Model\Asset;
4
5
use FAPI\Localise\Model\CreatableFromArray;
6
7
/**
8
 * @author Tobias Nyholm <[email protected]>
9
 */
10
class Asset implements CreatableFromArray
11
{
12
    /**
13
     * @var string
14
     */
15
    private $id;
16
17
    /**
18
     * @var string
19
     */
20
    private $type;
21
    /**
22
     * @var string
23
     */
24
    private $name;
25
    /**
26
     * @var string
27
     */
28
    private $context;
29
    /**
30
     * @var string
31
     */
32
    private $notes;
33
    /**
34
     * @var string
35
     */
36
    private $modified;
37
    /**
38
     * @var int
39
     */
40
    private $translated;
41
    /**
42
     * @var int
43
     */
44
    private $untranslated;
45
    /**
46
     * @var int
47
     */
48
    private $incomplate;
49
50
    /**
51
     * @var int
52
     */
53
    private $plural;
54
55
    /**
56
     * @var array
57
     */
58
    private $tags = [];
59
60
    private function __construct()
61
    {
62
    }
63
64
    /**
65
     * @param array $data
66
     *
67
     * @return Asset
68
     */
69
    public static function createFromArray(array $data)
70
    {
71
        $self = new self();
72
73
        if (isset($data['id'])) {
74
            $self->setId($data['id']);
75
        }
76
        if (isset($data['type'])) {
77
            $self->setType($data['type']);
78
        }
79
        if (isset($data['name'])) {
80
            $self->setType($data['type']);
81
        }
82
        if (isset($data['context'])) {
83
            $self->setContext($data['context']);
84
        }
85
        if (isset($data['notes'])) {
86
            $self->setNotes($data['notes']);
87
        }
88
        if (isset($data['modified'])) {
89
            $self->setModified($data['modified']);
90
        }
91
        if (isset($data['translated'])) {
92
            $self->setTranslated($data['translated']);
93
        }
94
        if (isset($data['untranslated'])) {
95
            $self->setUntranslated($data['untranslated']);
96
        }
97
        if (isset($data['incomplete'])) {
98
            $self->setIncomplate($data['incomplete']);
99
        }
100
        if (isset($data['plurals'])) {
101
            $self->setPlurals($data['plurals']);
102
        }
103
        if (isset($data['tags'])) {
104
            $self->setTags($data['tags']);
105
        }
106
107
        return $self;
108
    }
109
110
    /**
111
     * @return string
112
     */
113
    public function getId(): string
114
    {
115
        return $this->id;
116
    }
117
118
    /**
119
     * @param string $id
120
     */
121
    private function setId($id)
122
    {
123
        $this->id = $id;
124
    }
125
126
    /**
127
     * @return string
128
     */
129
    public function getType(): string
130
    {
131
        return $this->type;
132
    }
133
134
    /**
135
     * @param string $type
136
     */
137
    private function setType($type)
138
    {
139
        $this->type = $type;
140
    }
141
142
    /**
143
     * @return string
144
     */
145
    public function getName(): string
146
    {
147
        return $this->name;
148
    }
149
150
    /**
151
     * @param string $name
152
     */
153
    private function setName($name)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
154
    {
155
        $this->name = $name;
156
    }
157
158
    /**
159
     * @return string
160
     */
161
    public function getContext(): string
162
    {
163
        return $this->context;
164
    }
165
166
    /**
167
     * @param string $context
168
     */
169
    private function setContext($context)
170
    {
171
        $this->context = $context;
172
    }
173
174
    /**
175
     * @return string
176
     */
177
    public function getNotes(): string
178
    {
179
        return $this->notes;
180
    }
181
182
    /**
183
     * @param string $notes
184
     */
185
    private function setNotes($notes)
186
    {
187
        $this->notes = $notes;
188
    }
189
190
    /**
191
     * @return string
192
     */
193
    public function getModified(): string
194
    {
195
        return $this->modified;
196
    }
197
198
    /**
199
     * @param string $modified
200
     */
201
    private function setModified($modified)
202
    {
203
        $this->modified = $modified;
204
    }
205
206
    /**
207
     * @return int
208
     */
209
    public function getTranslated(): int
210
    {
211
        return $this->translated;
212
    }
213
214
    /**
215
     * @param int $translated
216
     */
217
    private function setTranslated($translated)
218
    {
219
        $this->translated = $translated;
220
    }
221
222
    /**
223
     * @return int
224
     */
225
    public function getUntranslated(): int
226
    {
227
        return $this->untranslated;
228
    }
229
230
    /**
231
     * @param int $untranslated
232
     */
233
    private function setUntranslated($untranslated)
234
    {
235
        $this->untranslated = $untranslated;
236
    }
237
238
    /**
239
     * @return int
240
     */
241
    public function getIncomplate(): int
242
    {
243
        return $this->incomplate;
244
    }
245
246
    /**
247
     * @param int $incomplate
248
     */
249
    private function setIncomplate($incomplate)
250
    {
251
        $this->incomplate = $incomplate;
252
    }
253
254
    /**
255
     * @return int
256
     */
257
    public function getPlurals(): int
258
    {
259
        return $this->plural;
260
    }
261
262
    /**
263
     * @param int $plural
264
     */
265
    private function setPlurals($plural)
266
    {
267
        $this->plural = $plural;
268
    }
269
270
    /**
271
     * @return array
272
     */
273
    public function getTags(): array
274
    {
275
        return $this->tags;
276
    }
277
278
    /**
279
     * @param array $tags
280
     */
281
    private function setTags($tags)
282
    {
283
        $this->tags = $tags;
284
    }
285
}
286