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 |
||
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() |
||
67 | |||
68 | /** |
||
69 | * Add a post to the game |
||
70 | * |
||
71 | * @param PostVotePost $post |
||
72 | * |
||
73 | * @return void |
||
74 | */ |
||
75 | public function addPost($post) |
||
79 | |||
80 | public function getPosts() |
||
84 | |||
85 | public function setPosts($posts) |
||
91 | |||
92 | /** |
||
93 | * @return the unknown_type |
||
94 | */ |
||
95 | public function getForm() |
||
99 | |||
100 | /** |
||
101 | * @param unknown_type $form |
||
102 | */ |
||
103 | public function setForm($form) |
||
109 | |||
110 | /** |
||
111 | * @return string unknown_type |
||
112 | */ |
||
113 | public function getPostDisplayMode() |
||
117 | |||
118 | /** |
||
119 | * @param unknown_type $postDisplayMode |
||
120 | */ |
||
121 | public function setPostDisplayMode($postDisplayMode) |
||
127 | |||
128 | /** |
||
129 | * @return int |
||
130 | */ |
||
131 | public function getPostDisplayNumber() |
||
135 | |||
136 | /** |
||
137 | * @param int $postDisplayNumber |
||
138 | * @return PostVote |
||
139 | */ |
||
140 | public function setPostDisplayNumber($postDisplayNumber) |
||
145 | |||
146 | /** |
||
147 | * @return the unknown_type |
||
148 | */ |
||
149 | public function getVoteAnonymous() |
||
153 | |||
154 | /** |
||
155 | * @param unknown_type $voteAnonymous |
||
156 | */ |
||
157 | public function setVoteAnonymous($voteAnonymous) |
||
163 | |||
164 | /** |
||
165 | * @return bool |
||
166 | */ |
||
167 | public function getModerationType() |
||
171 | |||
172 | /** |
||
173 | * @param bool $moderationType |
||
174 | */ |
||
175 | public function setModerationType($moderationType) |
||
181 | |||
182 | /** |
||
183 | * Convert the object to an array. |
||
184 | * |
||
185 | * @return array |
||
186 | */ |
||
187 | public function getArrayCopy() |
||
194 | |||
195 | /** |
||
196 | * Populate from an array. |
||
197 | * |
||
198 | * @param array $data |
||
199 | */ |
||
200 | View Code Duplication | public function populate($data = array()) |
|
212 | |||
213 | public function setInputFilter(InputFilterInterface $inputFilter) |
||
217 | |||
218 | public function getInputFilter() |
||
278 | } |
||
279 |
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..