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 WindowFactory extends WidgetFactory { |
||
| 20 | |||
| 21 | /** @var ManiaScriptFactory */ |
||
| 22 | protected $windowManiaScriptFactory; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * WindowFactory constructor. |
||
| 26 | * |
||
| 27 | * @param $name |
||
| 28 | * @param $sizeX |
||
| 29 | * @param $sizeY |
||
| 30 | * @param null $posX |
||
| 31 | * @param null $posY |
||
| 32 | * @param GuiHandler $guiHandler |
||
| 33 | * @param Factory $groupFactory |
||
| 34 | * @param ActionFactory $actionFactory |
||
| 35 | * @param ManiaScriptFactory $windowManiaScriptFactory |
||
| 36 | * @param Translations $translationsHelper |
||
| 37 | * @param string $className |
||
| 38 | */ |
||
| 39 | View Code Duplication | public function __construct( |
|
| 67 | |||
| 68 | |||
| 69 | |||
| 70 | /** |
||
| 71 | * @param Group $group |
||
| 72 | * |
||
| 73 | * @return Window |
||
| 74 | */ |
||
| 75 | protected function createManialink(Group $group) |
||
| 99 | |||
| 100 | public function closeManialink($login, $answerValues, $arguments) |
||
| 106 | } |
||
| 107 |
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.