Completed
Push — develop ( f8651f...893e32 )
by greg
02:30
created

MemoryCard   A

Complexity

Total Complexity 32

Size/Duplication

Total Lines 336
Duplicated Lines 2.68 %

Coupling/Cohesion

Components 3
Dependencies 3

Importance

Changes 0
Metric Value
wmc 32
lcom 3
cbo 3
dl 9
loc 336
rs 9.84
c 0
b 0
f 0

24 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createChrono() 0 5 1
A updateChrono() 0 4 1
A getId() 0 4 1
A setId() 0 6 1
A getTitle() 0 4 1
A setTitle() 0 6 1
A getDescription() 0 4 1
A setDescription() 0 6 1
A getImage() 0 4 1
A setImage() 0 6 1
A getGame() 0 4 1
A setGame() 0 6 1
A getJsonData() 0 4 1
A setJsonData() 0 6 1
A getCreatedAt() 0 4 1
A setCreatedAt() 0 6 1
A getUpdatedAt() 0 4 1
A setUpdatedAt() 0 6 1
A getArrayCopy() 0 6 1
A jsonSerialize() 0 13 1
B populate() 9 18 8
A setInputFilter() 0 4 1
A getInputFilter() 0 11 2

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 PlaygroundGame\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
8
use Doctrine\ORM\Mapping\PrePersist;
9
use Doctrine\ORM\Mapping\PreUpdate;
10
11
use Gedmo\Mapping\Annotation as Gedmo;
12
use Gedmo\Translatable\Translatable;
13
14
use Zend\InputFilter\Factory as InputFactory;
15
use Zend\InputFilter\InputFilter;
16
use Zend\InputFilter\InputFilterAwareInterface;
17
use Zend\InputFilter\InputFilterInterface;
18
19
/**
20
 * @ORM\Entity @HasLifecycleCallbacks
21
 * @ORM\Table(name="game_memory_card")
22
 * @Gedmo\TranslationEntity(class="PlaygroundGame\Entity\GameTranslation")
23
 */
24
25
class MemoryCard implements InputFilterAwareInterface, \JsonSerializable
26
{
27
    protected $inputFilter;
28
29
    /**
30
     * @ORM\Id
31
     * @ORM\Column(type="integer");
32
     * @ORM\GeneratedValue(strategy="AUTO")
33
     */
34
    protected $id;
35
36
    /**
37
     * @ORM\ManyToOne(targetEntity="Memory", inversedBy="cards")
38
     * @ORM\JoinColumn(name="game_id", referencedColumnName="id", onDelete="CASCADE")
39
     */
40
    protected $game;
41
42
    /**
43
     * @Gedmo\Translatable
44
     * @ORM\Column(type="string", length=255, nullable=false)
45
     */
46
    protected $title;
47
48
    /**
49
     * @Gedmo\Translatable
50
     * @ORM\Column(type="text", nullable=true)
51
     */
52
    protected $description;
53
54
    /**
55
     * @Gedmo\Translatable
56
     * @ORM\Column(name="image", type="string", length=255, nullable=true)
57
     */
58
    protected $image;
59
60
    /**
61
     * @ORM\Column(name="json_data", type="text", nullable=true)
62
     */
63
    protected $jsonData;
64
65
    /**
66
     * @ORM\Column(name="created_at", type="datetime")
67
     */
68
    protected $createdAt;
69
70
    /**
71
     * @ORM\Column(name="updated_at",type="datetime")
72
     */
73
    protected $updatedAt;
74
75
    public function __construct()
76
    {
77
        $this->cards = new ArrayCollection();
78
    }
79
80
    /**
81
     * @PrePersist
82
     */
83
    public function createChrono()
84
    {
85
        $this->createdAt = new \DateTime("now");
86
        $this->updatedAt = new \DateTime("now");
87
    }
88
89
    /**
90
     * @PreUpdate
91
     */
92
    public function updateChrono()
93
    {
94
        $this->updatedAt = new \DateTime("now");
95
    }
96
97
    /**
98
     * Gets the value of id.
99
     *
100
     * @return mixed
101
     */
102
    public function getId()
103
    {
104
        return $this->id;
105
    }
106
107
    /**
108
     * Sets the value of id.
109
     *
110
     * @param mixed $id the id
111
     *
112
     * @return self
113
     */
114
    public function setId($id)
115
    {
116
        $this->id = $id;
117
118
        return $this;
119
    }
120
121
    /**
122
     * Gets the value of title.
123
     *
124
     * @return mixed
125
     */
126
    public function getTitle()
127
    {
128
        return $this->title;
129
    }
130
131
    /**
132
     * Sets the value of title.
133
     *
134
     * @param mixed $title the title
135
     *
136
     * @return self
137
     */
138
    public function setTitle($title)
139
    {
140
        $this->title = $title;
141
142
        return $this;
143
    }
144
145
    /**
146
     * Gets the value of description.
147
     *
148
     * @return mixed
149
     */
150
    public function getDescription()
151
    {
152
        return $this->description;
153
    }
154
155
    /**
156
     * Sets the value of description.
157
     *
158
     * @param mixed $description the description
159
     *
160
     * @return self
161
     */
162
    public function setDescription($description)
163
    {
164
        $this->description = $description;
165
166
        return $this;
167
    }
168
169
    /**
170
     * Gets the value of image.
171
     *
172
     * @return mixed
173
     */
174
    public function getImage()
175
    {
176
        return $this->image;
177
    }
178
179
    /**
180
     * Sets the value of image.
181
     *
182
     * @param mixed $image the image
183
     *
184
     * @return self
185
     */
186
    public function setImage($image)
187
    {
188
        $this->image = $image;
189
190
        return $this;
191
    }
192
193
    /**
194
     * Gets the value of game.
195
     *
196
     * @return mixed
197
     */
198
    public function getGame()
199
    {
200
        return $this->game;
201
    }
202
203
    /**
204
     * Sets the value of game.
205
     *
206
     * @param mixed $game the game
207
     *
208
     * @return self
209
     */
210
    public function setGame($game)
211
    {
212
        $this->game = $game;
213
214
        return $this;
215
    }
216
217
    /**
218
     * Gets the value of jsonData.
219
     *
220
     * @return mixed
221
     */
222
    public function getJsonData()
223
    {
224
        return $this->jsonData;
225
    }
226
227
    /**
228
     * Sets the value of jsonData.
229
     *
230
     * @param mixed $jsonData the json data
231
     *
232
     * @return self
233
     */
234
    public function setJsonData($jsonData)
235
    {
236
        $this->jsonData = $jsonData;
237
238
        return $this;
239
    }
240
241
    /**
242
     * Gets the value of createdAt.
243
     *
244
     * @return mixed
245
     */
246
    public function getCreatedAt()
247
    {
248
        return $this->createdAt;
249
    }
250
251
    /**
252
     * Sets the value of createdAt.
253
     *
254
     * @param mixed $createdAt the created at
255
     *
256
     * @return self
257
     */
258
    public function setCreatedAt($createdAt)
259
    {
260
        $this->createdAt = $createdAt;
261
262
        return $this;
263
    }
264
265
    /**
266
     * Gets the value of updatedAt.
267
     *
268
     * @return mixed
269
     */
270
    public function getUpdatedAt()
271
    {
272
        return $this->updatedAt;
273
    }
274
275
    /**
276
     * Sets the value of updatedAt.
277
     *
278
     * @param mixed $updatedAt the updated at
279
     *
280
     * @return self
281
     */
282
    public function setUpdatedAt($updatedAt)
283
    {
284
        $this->updatedAt = $updatedAt;
285
286
        return $this;
287
    }
288
289
    /**
290
     * Convert the object to an array.
291
     *
292
     * @return array
293
     */
294
    public function getArrayCopy()
295
    {
296
        $obj_vars = get_object_vars($this);
297
298
        return $obj_vars;
299
    }
300
301
    /**
302
     * Convert the object to json.
303
     *
304
     * @return array
305
     */
306
    public function jsonSerialize()
307
    {
308
        $jsonArray = $this->getArrayCopy();
309
        unset($jsonArray['inputFilter']);
310
        unset($jsonArray['__initializer__']);
311
        unset($jsonArray['__cloner__']);
312
        unset($jsonArray['__isInitialized__']);
313
        unset($jsonArray['game']);
314
        unset($jsonArray['createdAt']);
315
        unset($jsonArray['updatedAt']);
316
317
        return $jsonArray;
318
    }
319
320
    /**
321
     * Populate from an array.
322
     *
323
     * @param array $data
324
     */
325
    public function populate($data = array())
326
    {
327 View Code Duplication
        if (isset($data['title']) && $data['title'] !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
328
            $this->title = $data['title'];
329
        }
330
331 View Code Duplication
        if (isset($data['description']) && $data['description'] !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
332
            $this->description = $data['description'];
333
        }
334
335 View Code Duplication
        if (isset($data['jsonData']) && $data['jsonData'] !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
336
            $this->jsonData = $data['jsonData'];
337
        }
338
339
        if (!empty($data['image'])) {
340
            $this->image = $data['image'];
341
        }
342
    }
343
344
    public function setInputFilter(InputFilterInterface $inputFilter)
345
    {
346
        throw new \Exception("Not used");
347
    }
348
349
    public function getInputFilter()
350
    {
351
        if (!$this->inputFilter) {
352
            $inputFilter = new InputFilter();
353
            $factory     = new InputFactory();
0 ignored issues
show
Unused Code introduced by
$factory is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
354
355
            $this->inputFilter = $inputFilter;
356
        }
357
358
        return $this->inputFilter;
359
    }
360
}
361