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 |
||
| 20 | class ManialinkFactory implements ManialinkFactoryInterface |
||
| 21 | { |
||
| 22 | /** @var GuiHandler */ |
||
| 23 | protected $guiHandler; |
||
| 24 | |||
| 25 | /** @var Factory */ |
||
| 26 | protected $groupFactory; |
||
| 27 | |||
| 28 | /** @var ActionFactory */ |
||
| 29 | protected $actionFactory; |
||
| 30 | |||
| 31 | /** @var string */ |
||
| 32 | protected $name; |
||
| 33 | |||
| 34 | /** @var string */ |
||
| 35 | protected $className; |
||
| 36 | |||
| 37 | /** @var Group[] */ |
||
| 38 | protected $groups = []; |
||
| 39 | |||
| 40 | /** @var float|int */ |
||
| 41 | protected $sizeX; |
||
| 42 | |||
| 43 | /** @var float|int */ |
||
| 44 | protected $sizeY; |
||
| 45 | |||
| 46 | /** @var float|int */ |
||
| 47 | protected $posX; |
||
| 48 | |||
| 49 | /** @var float|int */ |
||
| 50 | protected $posY; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * ManialinkFactory constructor. |
||
| 54 | * |
||
| 55 | * @param $name |
||
| 56 | * @param $sizeX |
||
| 57 | * @param $sizeY |
||
| 58 | * @param null $posX |
||
| 59 | * @param null $posY |
||
| 60 | * @param ManialinkFactoryContext $context |
||
| 61 | */ |
||
| 62 | 4 | public function __construct( |
|
| 88 | |||
| 89 | /** |
||
| 90 | * @return string |
||
| 91 | */ |
||
| 92 | public function getId() |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @inheritdoc |
||
| 99 | * @param string|array|Group $group |
||
| 100 | */ |
||
| 101 | 4 | public function create($group) |
|
| 126 | |||
| 127 | /** |
||
| 128 | * @inheritdoc |
||
| 129 | * @param string|array|Group $group |
||
| 130 | */ |
||
| 131 | 1 | public function update($group) |
|
| 156 | |||
| 157 | /** |
||
| 158 | * Create content in the manialink. |
||
| 159 | * |
||
| 160 | * @param ManialinkInterface $manialink |
||
| 161 | * |
||
| 162 | */ |
||
| 163 | 3 | protected function createContent(ManialinkInterface $manialink) |
|
| 167 | |||
| 168 | /** |
||
| 169 | * Update content in the manialink. |
||
| 170 | * |
||
| 171 | * @param ManialinkInterface $manialink |
||
| 172 | * |
||
| 173 | */ |
||
| 174 | 4 | protected function updateContent(ManialinkInterface $manialink) |
|
| 178 | |||
| 179 | /** |
||
| 180 | * @inheritdoc |
||
| 181 | */ |
||
| 182 | 1 | public function destroy(Group $group) |
|
| 189 | |||
| 190 | /** |
||
| 191 | * Create manialink object for user group. |
||
| 192 | * |
||
| 193 | * @param Group $group |
||
| 194 | * |
||
| 195 | * @return Manialink |
||
| 196 | */ |
||
| 197 | 3 | protected function createManialink(Group $group) |
|
| 203 | } |
||
| 204 |
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.