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 |
||
| 18 | class InstantWin extends Game implements InputFilterAwareInterface |
||
| 19 | { |
||
| 20 | const CLASSTYPE = 'instantwin'; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * values : datetime - dates of win |
||
| 24 | * code - winning and loosing codes are registered for the game |
||
| 25 | * visit - a winning is triggered every n visits, |
||
| 26 | * random - Not set by default : The number of wins is set and it's triggered randomly |
||
| 27 | * based on number of visitors + duration of game + number of wins |
||
| 28 | * |
||
| 29 | * @ORM\Column(name="occurrence_type", type="string", nullable=false) |
||
| 30 | */ |
||
| 31 | protected $occurrenceType = 'datetime'; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Automatic Draw |
||
| 35 | * @ORM\Column(name="schedule_occurrence_auto", type="boolean", nullable=false) |
||
| 36 | */ |
||
| 37 | protected $scheduleOccurrenceAuto = 0; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Determine how much occurrences to create |
||
| 41 | * |
||
| 42 | * @ORM\Column(name="occurrence_number", type="integer", nullable=true) |
||
| 43 | */ |
||
| 44 | protected $occurrenceNumber = 0; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Determine how much winning occurrences to create among the occurrences |
||
| 48 | * |
||
| 49 | * @ORM\Column(name="winning_occurrence_number", type="integer", nullable=true) |
||
| 50 | */ |
||
| 51 | protected $winningOccurrenceNumber = 0; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * this field is taken into account only if $occurrenceNumber<>0. |
||
| 55 | * if 'game' $occurrenceNumber are drawn between game start date and game end date |
||
| 56 | * if 'hour' $occurrenceNumber are drawn a hour between game start date and game end date |
||
| 57 | * if 'day' $occurrenceNumber are drawn a day for each day between game start date and game end date |
||
| 58 | * if 'week' $occurrenceNumber are drawn a week between game start date and game end date |
||
| 59 | * if 'month' $occurrenceNumber are drawn a month between game start date and game end date |
||
| 60 | * |
||
| 61 | * @ORM\Column(name="occurrence_draw_frequency", type="string", nullable=true) |
||
| 62 | */ |
||
| 63 | protected $occurrenceDrawFrequency; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @Gedmo\Translatable |
||
| 67 | * @ORM\Column(name="scratchcard_image", type="string", length=255, nullable=true) |
||
| 68 | */ |
||
| 69 | protected $scratchcardImage; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @ORM\OneToMany(targetEntity="InstantWinOccurrence", mappedBy="instant_win") |
||
| 73 | **/ |
||
| 74 | private $occurrences; |
||
| 75 | |||
| 76 | public function __construct() |
||
| 82 | |||
| 83 | /** |
||
| 84 | */ |
||
| 85 | public function setOccurrences($occurrences) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Get question. |
||
| 94 | * |
||
| 95 | * @return \Doctrine\Common\Collections\Collection |
||
| 96 | */ |
||
| 97 | public function getOccurrences() |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Add a question to the quiz. |
||
| 104 | * |
||
| 105 | * |
||
| 106 | * @return void |
||
| 107 | */ |
||
| 108 | public function addOccurrence($occurrence) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @return string unknown_type |
||
| 115 | */ |
||
| 116 | public function getOccurrenceType() |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @param unknown_type $occurrenceType |
||
| 123 | */ |
||
| 124 | public function setOccurrenceType($occurrenceType) |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @return the unknown_type |
||
| 133 | */ |
||
| 134 | public function getOccurrenceNumber() |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @param unknown_type $occurrenceNumber |
||
| 141 | */ |
||
| 142 | public function setOccurrenceNumber($occurrenceNumber) |
||
| 148 | /** |
||
| 149 | * @return the unknown_type |
||
| 150 | */ |
||
| 151 | public function getWinningOccurrenceNumber() |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @param unknown_type $winningOccurrenceNumber |
||
| 158 | */ |
||
| 159 | public function setWinningOccurrenceNumber($winningOccurrenceNumber) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @return the unknown_type |
||
| 168 | */ |
||
| 169 | public function getOccurrenceDrawFrequency() |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @param unknown_type $occurrenceDrawFrequency |
||
| 176 | */ |
||
| 177 | public function setOccurrenceDrawFrequency($occurrenceDrawFrequency) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @return integer unknown_type |
||
| 186 | */ |
||
| 187 | public function getScheduleOccurrenceAuto() |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @param unknown_type $scheduleOccurrenceAuto |
||
| 194 | */ |
||
| 195 | public function setScheduleOccurrenceAuto($scheduleOccurrenceAuto) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * |
||
| 204 | * @return the $scratchcardImage |
||
| 205 | */ |
||
| 206 | public function getScratchcardImage() |
||
| 210 | |||
| 211 | /** |
||
| 212 | * |
||
| 213 | * @param field_type $scratchcardImage |
||
| 214 | */ |
||
| 215 | public function setScratchcardImage($scratchcardImage) |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Convert the object to an array. |
||
| 224 | * |
||
| 225 | * @return array |
||
| 226 | */ |
||
| 227 | public function getArrayCopy() |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Populate from an array. |
||
| 237 | * |
||
| 238 | * @param array $data |
||
| 239 | */ |
||
| 240 | public function populate($data = array()) |
||
| 260 | |||
| 261 | public function setInputFilter(InputFilterInterface $inputFilter) |
||
| 265 | |||
| 266 | public function getInputFilter() |
||
| 331 | } |
||
| 332 |
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..