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 |
||
41 | class Category extends \Model { |
||
42 | |||
43 | public static $objectName = 'Категория магазина'; |
||
44 | public static $treeCategory = 'Ecommerce\Item'; |
||
45 | public static $cols = [ |
||
46 | //Основные параметры |
||
47 | 'parent_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'parent'], |
||
48 | 'name' => ['type' => 'text'], |
||
49 | 'alias' => ['type' => 'text'], |
||
50 | 'viewer' => ['type' => 'select', 'source' => 'method', 'method' => 'viewsCategoryList', 'module' => 'Ecommerce'], |
||
51 | 'template' => ['type' => 'select', 'source' => 'method', 'method' => 'templatesCategoryList', 'module' => 'Ecommerce'], |
||
52 | 'description' => ['type' => 'html'], |
||
53 | 'image_file_id' => ['type' => 'image'], |
||
54 | 'icon_file_id' => ['type' => 'image'], |
||
55 | 'options_inherit' => ['type' => 'bool'], |
||
56 | 'hidden' => ['type' => 'bool'], |
||
57 | //Системные |
||
58 | 'views' => ['type' => 'number', 'logging' => false], |
||
59 | 'imported' => ['type' => 'bool'], |
||
60 | 'weight' => ['type' => 'number'], |
||
61 | 'items_count' => ['type' => 'number'], |
||
62 | 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
||
63 | 'tree_path' => ['type' => 'text'], |
||
64 | 'date_create' => ['type' => 'dateTime'], |
||
65 | //Менеджеры |
||
66 | 'options' => ['type' => 'dataManager', 'relation' => 'options'], |
||
67 | ]; |
||
68 | public static $labels = [ |
||
69 | 'name' => 'Название', |
||
70 | 'alias' => 'Алиас', |
||
71 | 'parent_id' => 'Родительская категория', |
||
72 | 'icon_file_id' => 'Иконка', |
||
73 | 'image_file_id' => 'Изображение', |
||
74 | 'description' => 'Описание', |
||
75 | 'options_inherit' => 'Наследовать набор свойств', |
||
76 | 'options' => 'Свойства товаров', |
||
77 | 'hidden' => 'Скрытая' |
||
78 | ]; |
||
79 | public static $forms = [ |
||
80 | 'manager' => [ |
||
81 | 'map' => [ |
||
82 | ['name', 'alias'], |
||
83 | ['parent_id', 'image_file_id', 'icon_file_id'], |
||
84 | ['viewer', 'template'], |
||
85 | ['options_inherit', 'hidden'], |
||
86 | ['options'], |
||
87 | ['description'] |
||
88 | ] |
||
89 | ] |
||
90 | ]; |
||
91 | |||
92 | public static function indexes() { |
||
108 | |||
109 | public static function relations() { |
||
144 | |||
145 | public static $dataManagers = [ |
||
146 | 'manager' => [ |
||
147 | 'name' => 'Категории товаров', |
||
148 | 'cols' => [ |
||
149 | 'name', |
||
150 | 'image_file_id', |
||
151 | 'parent_id', |
||
152 | ], |
||
153 | 'sortMode' => true |
||
154 | ] |
||
155 | ]; |
||
156 | |||
157 | View Code Duplication | public function getRoot() { |
|
167 | |||
168 | public function beforeSave() { |
||
174 | |||
175 | public function beforeDelete() { |
||
180 | |||
181 | View Code Duplication | public function resolveTemplate() { |
|
190 | |||
191 | View Code Duplication | public function resolveViewer() { |
|
200 | |||
201 | public function calcItemsCount($save = true) { |
||
215 | } |