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 |
||
31 | class ElemSelect implements ModelInterface, ElemInterface |
||
32 | { |
||
33 | /** |
||
34 | * A unique id for the select field |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | private $sName; |
||
39 | /** |
||
40 | * @var \mrcnpdlk\Grandstream\XMLApp\Application\Model\Styles |
||
41 | */ |
||
42 | private $oStyles; |
||
43 | |||
44 | /** |
||
45 | * @var array |
||
46 | */ |
||
47 | private $tItems; |
||
48 | |||
49 | /** |
||
50 | * ElemSelect constructor. |
||
51 | * |
||
52 | * @param string $sName |
||
53 | */ |
||
54 | public function __construct(string $sName) |
||
59 | |||
60 | /** |
||
61 | * @param Styles $oStyles |
||
62 | * |
||
63 | * @return \mrcnpdlk\Grandstream\XMLApp\Application\Model\Components\ElemSelect |
||
64 | */ |
||
65 | View Code Duplication | public function setStyles(Styles $oStyles = null) |
|
74 | |||
75 | /** |
||
76 | * @return \mrcnpdlk\Grandstream\XMLApp\MyXML |
||
77 | */ |
||
78 | public function getXml(): MyXML |
||
96 | |||
97 | /** |
||
98 | * @return \mrcnpdlk\Grandstream\XMLApp\Application\Model\Styles |
||
99 | */ |
||
100 | public function getStyles() |
||
104 | |||
105 | /** |
||
106 | * @param string $sName |
||
107 | * @param string $sValue |
||
108 | * |
||
109 | * @return ElemSelect |
||
110 | */ |
||
111 | public function addItem(string $sName, string $sValue) |
||
120 | |||
121 | /** |
||
122 | * @param int $iX |
||
123 | * @param int $iY |
||
124 | * |
||
125 | * @return \mrcnpdlk\Grandstream\XMLApp\Application\Model\Components\ElemSelect |
||
126 | */ |
||
127 | public function move(int $iX, int $iY) |
||
133 | } |
||
134 |
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.