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 |
||
9 | class AdminActions |
||
10 | { |
||
11 | protected static $panelButtons = []; |
||
12 | |||
13 | /** |
||
14 | * Get edit area id for specific type |
||
15 | * |
||
16 | * @param CBitrixComponentTemplate $template |
||
17 | * @param $type |
||
18 | * @param $element |
||
19 | * @return string |
||
20 | */ |
||
21 | public static function getEditArea($template, $type, $element) |
||
25 | |||
26 | /** |
||
27 | * @param CBitrixComponentTemplate $template |
||
28 | * @param $element |
||
29 | */ |
||
30 | View Code Duplication | public static function editIBlockElement($template, $element) |
|
41 | |||
42 | /** |
||
43 | * @param CBitrixComponentTemplate $template |
||
44 | * @param $element |
||
45 | * @param string $confirm |
||
46 | */ |
||
47 | View Code Duplication | public static function deleteIBlockElement($template, $element, $confirm = 'Вы уверены что хотите удалить элемент?') |
|
58 | |||
59 | /** |
||
60 | * @param CBitrixComponentTemplate $template |
||
61 | * @param $section |
||
62 | */ |
||
63 | View Code Duplication | public static function editIBlockSection($template, $section) |
|
74 | |||
75 | /** |
||
76 | * @param CBitrixComponentTemplate $template |
||
77 | * @param $section |
||
78 | * @param string $confirm |
||
79 | */ |
||
80 | View Code Duplication | public static function deleteIBlockSection($template, $section, $confirm = 'Вы уверены что хотите удалить раздел?') |
|
91 | |||
92 | /** |
||
93 | * @param CBitrixComponentTemplate $template |
||
94 | * @param $element |
||
95 | * @param string $label |
||
96 | */ |
||
97 | View Code Duplication | public static function editHLBlockElement($template, $element, $label = 'Изменить элемент') |
|
108 | |||
109 | /** |
||
110 | * @param CBitrixComponentTemplate $template |
||
111 | * @param $element |
||
112 | * @param string $label |
||
113 | * @param string $confirm |
||
114 | */ |
||
115 | View Code Duplication | public static function deleteHLBlockElement($template, $element, $label = 'Удалить элемент', $confirm = 'Вы уверены что хотите удалить элемент?') |
|
126 | |||
127 | /** |
||
128 | * @param $element |
||
129 | * @return array |
||
130 | */ |
||
131 | View Code Duplication | protected static function getIBlockElementPanelButtons($element) |
|
144 | |||
145 | /** |
||
146 | * @param $section |
||
147 | * @return array |
||
148 | */ |
||
149 | View Code Duplication | protected static function getIBlockSectionPanelButtons($section) |
|
162 | } |
||
163 |
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.