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 WidgetFactory extends ManialinkFactory { |
||
| 20 | |||
| 21 | /** @var Translations */ |
||
| 22 | protected $translationsHelper; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * WidgetFactory 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 Translations $translationsHelper |
||
| 36 | * @param string $className |
||
| 37 | */ |
||
| 38 | View Code Duplication | public function __construct( |
|
| 67 | |||
| 68 | /** |
||
| 69 | * @param Group $group |
||
| 70 | * |
||
| 71 | * @return Window |
||
| 72 | */ |
||
| 73 | protected function createManialink(Group $group) |
||
| 88 | } |
||
| 89 |
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.