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 |
||
10 | class IBlockPropertyEnum |
||
11 | { |
||
12 | use FieldConstructor; |
||
13 | |||
14 | /** |
||
15 | * Добавить значение списка |
||
16 | * @throws \Exception |
||
17 | */ |
||
18 | View Code Duplication | public function add() |
|
32 | |||
33 | /** |
||
34 | * Обновить свойство инфоблока |
||
35 | * @param $id |
||
36 | * @throws \Exception |
||
37 | */ |
||
38 | View Code Duplication | public function update($id) |
|
47 | |||
48 | /** |
||
49 | * Удалить свойство инфоблока |
||
50 | * @param $id |
||
51 | * @throws \Exception |
||
52 | */ |
||
53 | public static function delete($id) |
||
61 | |||
62 | /** |
||
63 | * Установить настройки для добавления значения enum инфоблока по умолчанию |
||
64 | * @param string $xml_id |
||
65 | * @param string $value |
||
66 | * @param int $propertyId |
||
67 | * @return $this |
||
68 | */ |
||
69 | public function constructDefault($xml_id, $value, $propertyId = null) |
||
79 | |||
80 | /** |
||
81 | * Код свойства. |
||
82 | * @param string $propertyId |
||
83 | * @return $this |
||
84 | */ |
||
85 | public function setPropertyId($propertyId) |
||
91 | |||
92 | /** |
||
93 | * Внешний код. |
||
94 | * @param string $xml_id |
||
95 | * @return $this |
||
96 | */ |
||
97 | public function setXmlId($xml_id) |
||
103 | |||
104 | /** |
||
105 | * Индекс сортировки. |
||
106 | * @param int $sort |
||
107 | * @return $this |
||
108 | */ |
||
109 | public function setSort($sort = 500) |
||
115 | |||
116 | /** |
||
117 | * Значение варианта свойства. |
||
118 | * @param string $value |
||
119 | * @return $this |
||
120 | */ |
||
121 | public function setValue($value) |
||
127 | |||
128 | /** |
||
129 | * Значение варианта свойства. |
||
130 | * @param bool $def |
||
131 | * @return $this |
||
132 | */ |
||
133 | public function setDef($def) |
||
139 | } |
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.