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 |
||
| 16 | class Lottery extends Game implements InputFilterAwareInterface |
||
| 17 | { |
||
| 18 | const CLASSTYPE = 'lottery'; |
||
| 19 | /** |
||
| 20 | * Automatic Draw |
||
| 21 | * @ORM\Column(name="draw_auto", type="boolean", nullable=false) |
||
| 22 | */ |
||
| 23 | protected $drawAuto = 0; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @ORM\Column(name="draw_date", type="datetime", nullable=true) |
||
| 27 | */ |
||
| 28 | protected $drawDate; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @ORM\Column(type="integer", nullable=false) |
||
| 32 | */ |
||
| 33 | protected $winners; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @ORM\Column(type="integer", nullable=false) |
||
| 37 | */ |
||
| 38 | protected $substitutes; |
||
| 39 | |||
| 40 | public function __construct() |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @return integer |
||
| 48 | */ |
||
| 49 | public function getDrawAuto() |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @param integer $drawAuto |
||
| 56 | */ |
||
| 57 | public function setDrawAuto($drawAuto) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @return integer |
||
| 66 | */ |
||
| 67 | public function getWinners() |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @param integer $winners |
||
| 74 | */ |
||
| 75 | public function setWinners($winners) |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @return integer |
||
| 84 | */ |
||
| 85 | public function getSubstitutes() |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @param integer $substitutes |
||
| 92 | */ |
||
| 93 | public function setSubstitutes($substitutes) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @return \DateTime |
||
| 102 | */ |
||
| 103 | public function getDrawDate() |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param \DateTime $drawDate |
||
| 110 | */ |
||
| 111 | public function setDrawDate($drawDate) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Convert the object to an array. |
||
| 120 | * |
||
| 121 | * @return array |
||
| 122 | */ |
||
| 123 | public function getArrayCopy() |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Populate from an array. |
||
| 137 | * |
||
| 138 | * @param array $data |
||
| 139 | */ |
||
| 140 | View Code Duplication | public function populate($data = array()) |
|
| 151 | |||
| 152 | public function setInputFilter(InputFilterInterface $inputFilter) |
||
| 156 | |||
| 157 | View Code Duplication | public function getInputFilter() |
|
| 175 | } |
||
| 176 |
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.