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 |
||
19 | class Mission extends Game implements InputFilterAwareInterface |
||
20 | { |
||
21 | const CLASSTYPE = 'mission'; |
||
22 | |||
23 | /** |
||
24 | * @ORM\OneToMany(targetEntity="MissionGame", mappedBy="mission", cascade={"persist","remove"}, orphanRemoval=true) |
||
25 | */ |
||
26 | protected $missionGames; |
||
27 | |||
28 | public function __construct() |
||
34 | |||
35 | /** |
||
36 | * @return the $missionGames |
||
37 | */ |
||
38 | public function getMissionGames() |
||
42 | |||
43 | /** |
||
44 | * @param \PlaygroundGame\Entity\ArrayCollection $missionGames |
||
45 | */ |
||
46 | public function setMissionGames($missionGames) |
||
52 | |||
53 | public function addMissionGames(ArrayCollection $missionGames) |
||
60 | |||
61 | public function removeMissionGames(ArrayCollection $missionGames) |
||
68 | |||
69 | /** |
||
70 | * Add a game to the mission. |
||
71 | * |
||
72 | * @param MissionGame $missionGame |
||
73 | * |
||
74 | * @return void |
||
75 | */ |
||
76 | public function addMissionGame($missionGame) |
||
80 | |||
81 | /** |
||
82 | * Get the playables game if any |
||
83 | * |
||
84 | * @return array |
||
85 | */ |
||
86 | public function getPlayableGames($entry = null) |
||
100 | |||
101 | /** |
||
102 | * Get the next playable game if any |
||
103 | * |
||
104 | * @return \PlaygroundGame\Entity\Game |
||
105 | */ |
||
106 | public function getNextPlayableGame($entry = null) |
||
112 | |||
113 | /** |
||
114 | * is this game playable ? |
||
115 | * |
||
116 | * @return boolean |
||
117 | */ |
||
118 | public function isPlayable($subGame, $entry = null) |
||
133 | |||
134 | /** |
||
135 | * Convert the object to an array. |
||
136 | * |
||
137 | * @return array |
||
138 | */ |
||
139 | public function getArrayCopy() |
||
143 | |||
144 | /** |
||
145 | * Populate from an array. |
||
146 | * |
||
147 | * @param array $data |
||
148 | */ |
||
149 | public function populate($data = array()) |
||
153 | |||
154 | View Code Duplication | public function getInputFilter() |
|
174 | } |
||
175 |
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.