Completed
Pull Request — master (#254)
by greg
03:06
created

Prize::setCreatedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
namespace PlaygroundGame\Entity;
3
4
use Doctrine\ORM\Mapping as ORM;
5
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
6
use Doctrine\ORM\Mapping\PrePersist;
7
use Doctrine\ORM\Mapping\PreUpdate;
8
use Zend\InputFilter\InputFilter;
9
use Zend\InputFilter\Factory as InputFactory;
10
use Zend\InputFilter\InputFilterInterface;
11
12
/**
13
 * @ORM\Entity @HasLifecycleCallbacks
14
 * @ORM\Table(name="game_prize")
15
 */
16
class Prize implements \JsonSerializable
17
{
18
    protected $inputFilter;
19
20
    /**
21
     * @ORM\Id
22
     * @ORM\Column(type="integer");
23
     * @ORM\GeneratedValue(strategy="AUTO")
24
     */
25
    protected $id;
26
27
    /**
28
     * @ORM\ManyToOne(targetEntity="Game", inversedBy="prizes")
29
     *
30
     **/
31
    protected $game;
32
33
    /**
34
     * @ORM\Column(type="string", length=255, nullable=false)
35
     */
36
    protected $title;
37
38
    /**
39
     * @ORM\Column(type="string", length=255, nullable=false)
40
     */
41
    protected $identifier;
42
43
    /**
44
     * @ORM\ManyToOne(targetEntity="PrizeCategory")
45
     * @ORM\JoinColumn(name="prize_category_id", referencedColumnName="id")
46
     **/
47
    protected $prizeCategory;
48
49
    /**
50
     * @ORM\Column(name="prize_content",type="text", nullable=true)
51
     */
52
    protected $prizeContent;
53
54
    /**
55
     * @ORM\Column(type="integer", nullable=false)
56
     */
57
    protected $qty = 0;
58
59
    /**
60
     * @ORM\Column(name="unit_price", type="float", nullable=false)
61
     */
62
    protected $unitPrice = 1;
63
64
    /**
65
     * @ORM\Column(type="string", length=10, nullable=true)
66
     */
67
    protected $currency;
68
69
    /**
70
     * @ORM\Column(name="created_at", type="datetime")
71
     */
72
    protected $createdAt;
73
74
    /**
75
     * @ORM\Column(name="updated_at", type="datetime")
76
     */
77
    protected $updatedAt;
78
79
    /**
80
     * @ORM\Column(type="string", length=255, nullable=true)
81
     */
82
    protected $picture;
83
84
    /** @PrePersist */
85
    public function createChrono()
86
    {
87
        $this->createdAt = new \DateTime("now");
88
        $this->updatedAt = new \DateTime("now");
89
    }
90
91
    /** @PreUpdate */
92
    public function updateChrono()
93
    {
94
        $this->updatedAt = new \DateTime("now");
95
    }
96
97
    /**
98
     * @return the $id
99
     */
100
    public function getId()
101
    {
102
        return $this->id;
103
    }
104
105
    /**
106
     * @param field_type $id
107
     */
108
    public function setId($id)
109
    {
110
        $this->id = $id;
111
112
        return $this;
113
    }
114
115
    /**
116
     * @return the unknown_type
117
     */
118
    public function getGame()
119
    {
120
        return $this->game;
121
    }
122
123
    /**
124
     * @param unknown_type $game
125
     */
126
    public function setGame($game)
127
    {
128
        $this->game = $game;
129
130
        return $this;
131
    }
132
133
    /**
134
     * @return the $title
135
     */
136
    public function getTitle()
137
    {
138
        return $this->title;
139
    }
140
141
    /**
142
     * @param field_type $title
143
     */
144
    public function setTitle($title)
145
    {
146
        $this->title = $title;
147
148
        return $this;
149
    }
150
151
    /**
152
     * @return the $identifier
153
     */
154
    public function getIdentifier()
155
    {
156
        return $this->identifier;
157
    }
158
159
    /**
160
     * @param field_type $identifier
161
     */
162
    public function setIdentifier($identifier)
163
    {
164
        $this->identifier = $identifier;
165
166
        return $this;
167
    }
168
169
    /**
170
     * @return the $prizeCategory
171
     */
172
    public function getPrizeCategory()
173
    {
174
        return $this->prizeCategory;
175
    }
176
177
    /**
178
     * @param unknown $prizeCategory
179
     */
180
    public function setPrizeCategory($prizeCategory)
181
    {
182
        $this->prizeCategory = $prizeCategory;
183
184
        return $this;
185
    }
186
187
    /**
188
     * @return the $prizeContent
189
     */
190
    public function getPrizeContent()
191
    {
192
        return $this->prizeContent;
193
    }
194
195
    /**
196
     */
197
    public function setPrizeContent($prizeContent)
198
    {
199
        $this->prizeContent = $prizeContent;
200
201
        return $this;
202
    }
203
204
    /**
205
     * @return integer $qty
206
     */
207
    public function getQty()
208
    {
209
        return $this->qty;
210
    }
211
212
    /**
213
     * @param number $qty
214
     */
215
    public function setQty($qty)
216
    {
217
        $this->qty = $qty;
0 ignored issues
show
Documentation Bug introduced by
It seems like $qty can also be of type double. However, the property $qty is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
218
219
        return $this;
220
    }
221
222
    /**
223
     * @return integer $unitPrice
224
     */
225
    public function getUnitPrice()
226
    {
227
        return $this->unitPrice;
228
    }
229
230
    /**
231
     * @param number $unitPrice
232
     */
233
    public function setUnitPrice($unitPrice)
234
    {
235
        $this->unitPrice = $unitPrice;
0 ignored issues
show
Documentation Bug introduced by
It seems like $unitPrice can also be of type double. However, the property $unitPrice is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
236
237
        return $this;
238
    }
239
240
    /**
241
     * @return the $currency
242
     */
243
    public function getCurrency()
244
    {
245
        return $this->currency;
246
    }
247
248
    /**
249
     * @param field_type $currency
250
     */
251
    public function setCurrency($currency)
252
    {
253
        $this->currency = $currency;
254
255
        return $this;
256
    }
257
258
    /**
259
     * @return \DateTime $created_at
260
     */
261
    public function getCreatedAt()
262
    {
263
        return $this->createdAt;
264
    }
265
266
    /**
267
     * @param \DateTime $createdAt
268
     */
269
    public function setCreatedAt($createdAt)
270
    {
271
        $this->createdAt = $createdAt;
272
273
        return $this;
274
    }
275
276
    /**
277
     * @return \DateTime $updatedAt
278
     */
279
    public function getUpdatedAt()
280
    {
281
        return $this->updatedAt;
282
    }
283
284
    /**
285
     * @param \DateTime $updatedAt
286
     */
287
    public function setUpdatedAt($updatedAt)
288
    {
289
        $this->updatedAt = $updatedAt;
290
291
        return $this;
292
    }
293
294
    /**
295
     * @return the $picture
296
     */
297
    public function getPicture()
298
    {
299
        return $this->picture;
300
    }
301
302
    /**
303
     * @param field_type $picture
304
     */
305
    public function setPicture($picture)
306
    {
307
        $this->picture = $picture;
308
309
        return $this;
310
    }
311
312
    /**
313
     * Convert the object to an array.
314
     *
315
     * @return array
316
     */
317
    public function getArrayCopy()
318
    {
319
        $obj_vars = get_object_vars($this);
320
321
        return $obj_vars;
322
    }
323
324
    /**
325
    * Convert the object to json.
326
    *
327
    * @return array
328
    */
329
    public function jsonSerialize()
330
    {
331
        return $this->getArrayCopy();
332
    }
333
334
    /**
335
     * Populate from an array.
336
     *
337
     * @param array $data
338
     */
339
    public function populate($data = array())
340
    {
341
        if (isset($data['prizeContent']) && $data['prizeContent'] !== null) {
342
            $this->prizeContent = $data['prizeContent'];
343
        }
344
345 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...
346
            $this->title = $data['title'];
347
        }
348
349 View Code Duplication
        if (isset($data['qty']) && $data['qty'] !== 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...
350
            $this->qty = $data['qty'];
351
        }
352
353 View Code Duplication
        if (isset($data['identifier']) && $data['identifier'] !== 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...
354
            $this->identifier = $data['identifier'];
355
        }
356
357
        if (isset($data['unitPrice']) && $data['unitPrice'] !== null) {
358
            $this->unitPrice = $data['unitPrice'];
359
        }
360
361
        if (isset($data['currency']) && $data['currency'] !== null) {
362
            $this->currency = $data['currency'];
363
        }
364
365
        if (isset($data['picture']) && $data['picture'] !== null) {
366
            $this->picture = $data['picture'];
367
        }
368
    }
369
370
    /**
371
     * @return InputFilter $inputFilter
372
     */
373 View Code Duplication
    public function getInputFilter()
0 ignored issues
show
Duplication introduced by
This method 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...
374
    {
375
        if (!$this->inputFilter) {
376
            $inputFilter = new InputFilter();
377
            $factory = new InputFactory();
378
379
            $inputFilter->add($factory->createInput(array(
380
                'name' => 'identifier',
381
                'required' => true,
382
                'filters' => array(
383
                    array(
384
                        'name' => 'StripTags'
385
                    ),
386
                    array(
387
                        'name' => 'StringTrim'
388
                    ),
389
                    array(
390
                        'name' => 'PlaygroundCore\Filter\Slugify'
391
                    )
392
                ),
393
                'validators' => array(
394
                    array(
395
                        'name' => 'StringLength',
396
                        'options' => array(
397
                            'encoding' => 'UTF-8',
398
                            'min' => 3,
399
                            'max' => 255
400
                        )
401
                    )
402
                )
403
            )));
404
405
            $this->inputFilter = $inputFilter;
406
        }
407
408
        return $this->inputFilter;
409
    }
410
411
    /**
412
     * @param InputFilterInterface $inputFilter
413
     */
414
    public function setInputFilter(InputFilterInterface $inputFilter)
415
    {
416
        throw new \Exception("Not used");
417
    }
418
}
419