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 |
||
17 | class WindowFactory extends FmlManialinkFactory |
||
18 | { |
||
19 | |||
20 | /** @var WindowFrameFactory */ |
||
21 | protected $windowFrameFactory; |
||
22 | |||
23 | /** |
||
24 | * WindowFactory constructor. |
||
25 | * |
||
26 | * @param $name |
||
27 | * @param $sizeX |
||
28 | * @param $sizeY |
||
29 | * @param null $posX |
||
30 | * @param null $posY |
||
31 | * @param WindowFactoryContext $context |
||
32 | */ |
||
33 | View Code Duplication | public function __construct( |
|
54 | |||
55 | /** |
||
56 | * @param Group $group |
||
57 | * |
||
58 | * @return Window |
||
59 | */ |
||
60 | protected function createManialink(Group $group) |
||
87 | |||
88 | public function closeManialink(ManialinkInterface $manialink) |
||
92 | |||
93 | /** |
||
94 | * @param ManialinkInterface|Window $manialink |
||
95 | * @param bool|string $busyStatus |
||
96 | */ |
||
97 | public function setBusy(ManialinkInterface $manialink, $busyStatus = true) |
||
102 | |||
103 | |||
104 | } |
||
105 |
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.