Completed
Pull Request — master (#411)
by greg
02:27
created

PostVote::getPostDisplayMode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace PlaygroundGame\Entity;
3
4
use PlaygroundGame\Entity\Game;
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
8
use Zend\InputFilter\InputFilter;
9
use Zend\InputFilter\Factory as InputFactory;
10
use Zend\InputFilter\InputFilterAwareInterface;
11
use Zend\InputFilter\InputFilterInterface;
12
13
/**
14
 * @ORM\Entity @HasLifecycleCallbacks
15
 * @ORM\Table(name="game_postvote")
16
 */
17
class PostVote extends Game implements InputFilterAwareInterface
18
{
19
    const CLASSTYPE = 'postvote';
20
21
    /**
22
     * Display mode of Posts :
23
     * 'date' : sort by post date desc
24
     * 'random' : ...
25
     * 'votes' : sort by number of vote desc
26
     *
27
     * @ORM\Column(name="post_display_mode", type="string", nullable=false)
28
     */
29
    protected $postDisplayMode = 'date';
30
    
31
    /**
32
     * Number of Post displayed :
33
     * 0 : infinite
34
     *
35
     * @ORM\Column(name="post_display_number", type="integer", nullable=false)
36
     */
37
    protected $postDisplayNumber = 0;
38
39
    /**
40
     * Is it possible to vote ?
41
     * @ORM\Column(name="vote_active", type="boolean", nullable=false)
42
     */
43
    protected $voteActive = 1;
44
45
    /**
46
     * Is it possible to vote anonymously ?
47
     * @ORM\Column(name="vote_anonymous", type="boolean", nullable=false)
48
     */
49
    protected $voteAnonymous;
50
51
    /**
52
     * Type of moderation : moderate posts before their publication, or after their publication (default)
53
     * @ORM\Column(name="moderation_type", type="boolean", nullable=false, options={"default" = 0})
54
     */
55
    protected $moderationType = 0;
56
57
    /**
58
     * @ORM\OneToOne(targetEntity="PostVoteForm", mappedBy="postvote", cascade={"persist","remove"})
59
     **/
60
    private $form;
61
62
    /**
63
     * @ORM\OneToMany(targetEntity="PostVotePost", mappedBy="post_vote")
64
     **/
65
    private $posts;
66
67
    public function __construct()
68
    {
69
        parent::__construct();
70
        $this->setClassType(self::CLASSTYPE);
71
        $this->posts = new ArrayCollection();
72
    }
73
74
    /**
75
     * Add a post to the game
76
     *
77
     * @param PostVotePost $post
78
     *
79
     * @return void
80
     */
81
    public function addPost($post)
82
    {
83
        $this->post[] = $post;
0 ignored issues
show
Bug introduced by
The property post does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
84
    }
85
86
    public function getPosts()
87
    {
88
        return $this->posts;
89
    }
90
91
    public function setPosts($posts)
92
    {
93
        $this->posts = $posts;
94
95
        return $this;
96
    }
97
98
    /**
99
     * @return the unknown_type
100
     */
101
    public function getForm()
102
    {
103
        return $this->form;
104
    }
105
106
    /**
107
     * @param unknown_type $form
108
     */
109
    public function setForm($form)
110
    {
111
        $this->form = $form;
112
113
        return $this;
114
    }
115
116
    /**
117
     * @return string unknown_type
118
     */
119
    public function getPostDisplayMode()
120
    {
121
        return $this->postDisplayMode;
122
    }
123
124
    /**
125
     * @param unknown_type $postDisplayMode
126
     */
127
    public function setPostDisplayMode($postDisplayMode)
128
    {
129
        $this->postDisplayMode = $postDisplayMode;
0 ignored issues
show
Documentation Bug introduced by
It seems like $postDisplayMode of type object<PlaygroundGame\Entity\unknown_type> is incompatible with the declared type string of property $postDisplayMode.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
130
131
        return $this;
132
    }
133
    
134
    /**
135
     * @return int
136
     */
137
    public function getPostDisplayNumber()
138
    {
139
        return $this->postDisplayNumber;
140
    }
141
    
142
    /**
143
     * @param int $postDisplayNumber
144
     * @return PostVote
145
     */
146
    public function setPostDisplayNumber($postDisplayNumber)
147
    {
148
        $this->postDisplayNumber = $postDisplayNumber;
149
        return $this;
150
    }
151
152
    /**
153
     * @return the unknown_type
154
     */
155
    public function getVoteActive()
156
    {
157
        return $this->voteActive;
158
    }
159
160
    /**
161
     * @param unknown_type $voteActive
162
     */
163
    public function setVoteActive($voteActive)
164
    {
165
        $this->voteActive = $voteActive;
0 ignored issues
show
Documentation Bug introduced by
It seems like $voteActive of type object<PlaygroundGame\Entity\unknown_type> is incompatible with the declared type integer of property $voteActive.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
166
167
        return $this;
168
    }
169
170
    /**
171
     * @return the unknown_type
172
     */
173
    public function getVoteAnonymous()
174
    {
175
        return $this->voteAnonymous;
176
    }
177
178
    /**
179
     * @param unknown_type $voteAnonymous
180
     */
181
    public function setVoteAnonymous($voteAnonymous)
182
    {
183
        $this->voteAnonymous = $voteAnonymous;
184
185
        return $this;
186
    }
187
188
    /**
189
     * @return bool
190
     */
191
    public function getModerationType()
192
    {
193
        return $this->moderationType;
194
    }
195
196
    /**
197
     * @param bool $moderationType
198
     */
199
    public function setModerationType($moderationType)
200
    {
201
        $this->moderationType = $moderationType;
0 ignored issues
show
Documentation Bug introduced by
The property $moderationType was declared of type integer, but $moderationType is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
202
203
        return $this;
204
    }
205
206
    /**
207
     * Convert the object to an array.
208
     *
209
     * @return array
210
     */
211
    public function getArrayCopy()
212
    {
213
        $obj_vars = parent::getArrayCopy();
214
        array_merge($obj_vars, get_object_vars($this));
215
216
        return $obj_vars;
217
    }
218
219
    /**
220
     * Populate from an array.
221
     *
222
     * @param array $data
223
     */
224 View Code Duplication
    public function populate($data = array())
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...
225
    {
226
        parent::populate($data);
227
228
        if (isset($data['postDisplayMode']) && $data['postDisplayMode'] !== null) {
229
            $this->postDisplayMode = $data['postDisplayMode'];
230
        }
231
232
        if (isset($data['voteAnonymous']) && $data['voteAnonymous'] !== null) {
233
            $this->voteAnonymous = $data['voteAnonymous'];
234
        }
235
    }
236
237
    public function setInputFilter(InputFilterInterface $inputFilter)
238
    {
239
        throw new \Exception("Not used");
240
    }
241
242
    public function getInputFilter()
243
    {
244
        if (!$this->inputFilter) {
245
            $inputFilter = new InputFilter();
0 ignored issues
show
Unused Code introduced by
$inputFilter 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...
246
            $factory = new InputFactory();
247
248
            $inputFilter = parent::getInputFilter();
249
250
            $inputFilter->add(
251
                $factory->createInput(
252
                    array(
253
                        'name' => 'postDisplayMode',
254
                        'required' => false,
255
                        'validators' => array(
256
                            array(
257
                                'name' => 'InArray',
258
                                'options' => array(
259
                                    'haystack' => array('date', 'vote', 'random')
260
                                )
261
                            )
262
                        )
263
                    )
264
                )
265
            );
266
267
            $inputFilter->add(
268
                $factory->createInput(
269
                    array(
270
                        'name' => 'voteActive',
271
                        'required' => true,
272
                        'validators' => array(
273
                            array(
274
                                'name' => 'Between',
275
                                'options' => array('min' => 0, 'max' => 1)
276
                            )
277
                        )
278
                    )
279
                )
280
            );
281
282
            $inputFilter->add(
283
                $factory->createInput(
284
                    array(
285
                        'name' => 'voteAnonymous',
286
                        'required' => true,
287
                        'validators' => array(
288
                            array(
289
                                'name' => 'Between',
290
                                'options' => array('min' => 0, 'max' => 1)
291
                            )
292
                        )
293
                    )
294
                )
295
            );
296
297
            $inputFilter->add(
298
                $factory->createInput(
299
                    array(
300
                        'name' => 'moderationType',
301
                        'required' => false,
302
                        'validators' => array(
303
                            array(
304
                                'name' => 'Between',
305
                                'options' => array('min' => 0, 'max' => 1)
306
                            )
307
                        )
308
                    )
309
                )
310
            );
311
312
            $this->inputFilter = $inputFilter;
313
        }
314
315
        return $this->inputFilter;
316
    }
317
}
318