Completed
Push — master ( 3c9f39...7900b8 )
by greg
29:19 queued 15:31
created

PostVote::setTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
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 anonymously ?
41
     * @ORM\Column(name="vote_anonymous", type="boolean", nullable=false)
42
     */
43
    protected $voteAnonymous;
44
45
    /**
46
     * Type of moderation : moderate posts before their publication, or after their publication (default)
47
     * @ORM\Column(name="moderation_type", type="boolean", nullable=false, options={"default" = 0})
48
     */
49
    protected $moderationType = 0;
50
51
    /**
52
     * @ORM\OneToOne(targetEntity="PostVoteForm", mappedBy="postvote", cascade={"persist","remove"})
53
     **/
54
    private $form;
55
56
    /**
57
     * @ORM\OneToMany(targetEntity="PostVotePost", mappedBy="post_vote")
58
     **/
59
    private $posts;
60
61
    public function __construct()
62
    {
63
        parent::__construct();
64
        $this->setClassType(self::CLASSTYPE);
65
        $this->posts = new ArrayCollection();
66
    }
67
68
    /**
69
     * Add a post to the game
70
     *
71
     * @param PostVotePost $post
72
     *
73
     * @return void
74
     */
75
    public function addPost($post)
76
    {
77
        $this->post[] = $post;
78
    }
79
80
    public function getPosts()
81
    {
82
        return $this->posts;
83
    }
84
85
    public function setPosts($posts)
86
    {
87
        $this->posts = $posts;
88
89
        return $this;
90
    }
91
92
    /**
93
     * @return the unknown_type
94
     */
95
    public function getForm()
96
    {
97
        return $this->form;
98
    }
99
100
    /**
101
     * @param unknown_type $form
102
     */
103
    public function setForm($form)
104
    {
105
        $this->form = $form;
106
107
        return $this;
108
    }
109
110
    /**
111
     * @return string unknown_type
112
     */
113
    public function getPostDisplayMode()
114
    {
115
        return $this->postDisplayMode;
116
    }
117
118
    /**
119
     * @param unknown_type $postDisplayMode
120
     */
121
    public function setPostDisplayMode($postDisplayMode)
122
    {
123
        $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...
124
125
        return $this;
126
    }
127
    
128
    /**
129
     * @return int
130
     */
131
    public function getPostDisplayNumber()
132
    {
133
        return $this->postDisplayNumber;
134
    }
135
    
136
    /**
137
     * @param int $postDisplayNumber
138
     * @return PostVote
139
     */
140
    public function setPostDisplayNumber($postDisplayNumber)
141
    {
142
        $this->postDisplayNumber = $postDisplayNumber;
143
        return $this;
144
    }
145
146
    /**
147
     * @return the unknown_type
148
     */
149
    public function getVoteAnonymous()
150
    {
151
        return $this->voteAnonymous;
152
    }
153
154
    /**
155
     * @param unknown_type $voteAnonymous
156
     */
157
    public function setVoteAnonymous($voteAnonymous)
158
    {
159
        $this->voteAnonymous = $voteAnonymous;
160
161
        return $this;
162
    }
163
164
    /**
165
     * @return bool
166
     */
167
    public function getModerationType()
168
    {
169
        return $this->moderationType;
170
    }
171
172
    /**
173
     * @param bool $moderationType
174
     */
175
    public function setModerationType($moderationType)
176
    {
177
        $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...
178
179
        return $this;
180
    }
181
182
    /**
183
     * Convert the object to an array.
184
     *
185
     * @return array
186
     */
187
    public function getArrayCopy()
188
    {
189
        $obj_vars = parent::getArrayCopy();
190
        array_merge($obj_vars, get_object_vars($this));
191
192
        return $obj_vars;
193
    }
194
195
    /**
196
     * Populate from an array.
197
     *
198
     * @param array $data
199
     */
200 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...
201
    {
202
        parent::populate($data);
203
204
        if (isset($data['postDisplayMode']) && $data['postDisplayMode'] !== null) {
205
            $this->postDisplayMode = $data['postDisplayMode'];
206
        }
207
208
        if (isset($data['voteAnonymous']) && $data['voteAnonymous'] !== null) {
209
            $this->voteAnonymous = $data['voteAnonymous'];
210
        }
211
    }
212
213
    public function setInputFilter(InputFilterInterface $inputFilter)
214
    {
215
        throw new \Exception("Not used");
216
    }
217
218
    public function getInputFilter()
219
    {
220
        if (!$this->inputFilter) {
221
            $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...
222
            $factory = new InputFactory();
223
224
            $inputFilter = parent::getInputFilter();
225
226
            $inputFilter->add(
227
                $factory->createInput(
228
                    array(
229
                        'name' => 'postDisplayMode',
230
                        'required' => false,
231
                        'validators' => array(
232
                            array(
233
                                'name' => 'InArray',
234
                                'options' => array(
235
                                    'haystack' => array('date', 'vote', 'random')
236
                                )
237
                            )
238
                        )
239
                    )
240
                )
241
            );
242
243
            $inputFilter->add(
244
                $factory->createInput(
245
                    array(
246
                        'name' => 'voteAnonymous',
247
                        'required' => true,
248
                        'validators' => array(
249
                            array(
250
                                'name' => 'Between',
251
                                'options' => array('min' => 0, 'max' => 1)
252
                            )
253
                        )
254
                    )
255
                )
256
            );
257
258
            $inputFilter->add(
259
                $factory->createInput(
260
                    array(
261
                        'name' => 'moderationType',
262
                        'required' => false,
263
                        'validators' => array(
264
                            array(
265
                                'name' => 'Between',
266
                                'options' => array('min' => 0, 'max' => 1)
267
                            )
268
                        )
269
                    )
270
                )
271
            );
272
273
            $this->inputFilter = $inputFilter;
274
        }
275
276
        return $this->inputFilter;
277
    }
278
}
279