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 IBlockType |
||
| 11 | { |
||
| 12 | use FieldConstructor; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Добавить тип инфоблока |
||
| 16 | * @throws \Exception |
||
| 17 | */ |
||
| 18 | View Code Duplication | public function add() |
|
| 27 | |||
| 28 | /** |
||
| 29 | * Обновить тип инфоблока |
||
| 30 | * @param $id |
||
| 31 | * @throws \Exception |
||
| 32 | */ |
||
| 33 | View Code Duplication | public function update($id) |
|
| 42 | |||
| 43 | /** |
||
| 44 | * Удалить тип инфоблока |
||
| 45 | * @param $id |
||
| 46 | * @throws \Exception |
||
| 47 | */ |
||
| 48 | public static function delete($id) |
||
| 56 | |||
| 57 | /** |
||
| 58 | * ID типа информационных блоков. Уникален. |
||
| 59 | * @param string $id |
||
| 60 | * @return $this |
||
| 61 | */ |
||
| 62 | public function setId($id) |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Разделяются ли элементы блока этого типа по разделам. |
||
| 71 | * @param bool $has |
||
| 72 | * @return $this |
||
| 73 | */ |
||
| 74 | public function setSections($has = true) |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Полный путь к файлу-обработчику массива полей элемента перед сохранением на странице редактирования элемента. |
||
| 83 | * @param string $editFileBefore |
||
| 84 | * @return $this |
||
| 85 | */ |
||
| 86 | public function setEditFileBefore($editFileBefore) |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Полный путь к файлу-обработчику вывода интерфейса редактирования элемента. |
||
| 95 | * @param string $editFileAfter |
||
| 96 | * @return $this |
||
| 97 | */ |
||
| 98 | public function setEditFileAfter($editFileAfter) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Блоки данного типа экспортировать в RSS |
||
| 107 | * @param bool $inRss |
||
| 108 | * @return $this |
||
| 109 | */ |
||
| 110 | public function setInRss($inRss = false) |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Порядок сортировки типа |
||
| 119 | * @param int $sort |
||
| 120 | * @return $this |
||
| 121 | */ |
||
| 122 | public function setSort($sort = 500) |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Указать языковые фразы |
||
| 131 | * @param string $lang ключ языка (ru) |
||
| 132 | * @param string $name |
||
| 133 | * @param string $sectionName |
||
| 134 | * @param string $elementName |
||
| 135 | * @return $this |
||
| 136 | */ |
||
| 137 | public function setLang($lang, $name, $sectionName = null, $elementName = null) |
||
| 152 | } |
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.