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 |
||
14 | class Category extends \Model { |
||
15 | |||
16 | public static $objectName = 'Категория магазина'; |
||
17 | public static $treeCategory = 'Ecommerce\Item'; |
||
18 | public static $cols = [ |
||
19 | //Основные параметры |
||
20 | 'parent_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'parent'], |
||
21 | 'name' => ['type' => 'text'], |
||
22 | 'alias' => ['type' => 'text'], |
||
23 | 'viewer' => ['type' => 'select', 'source' => 'method', 'method' => 'viewsCategoryList', 'module' => 'Ecommerce'], |
||
24 | 'template' => ['type' => 'select', 'source' => 'method', 'method' => 'templatesCategoryList', 'module' => 'Ecommerce'], |
||
25 | 'description' => ['type' => 'html'], |
||
26 | 'image_file_id' => ['type' => 'image'], |
||
27 | 'options_inherit' => ['type' => 'bool'], |
||
28 | //Системные |
||
29 | 'imported' => ['type' => 'bool'], |
||
30 | 'weight' => ['type' => 'number'], |
||
31 | 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
||
32 | 'tree_path' => ['type' => 'text'], |
||
33 | 'date_create' => ['type' => 'dateTime'], |
||
34 | //Менеджеры |
||
35 | 'options' => ['type' => 'dataManager', 'relation' => 'options'], |
||
36 | ]; |
||
37 | public static $labels = [ |
||
38 | 'name' => 'Название', |
||
39 | 'alias' => 'Алиас', |
||
40 | 'parent_id' => 'Родительская категория', |
||
41 | 'image_file_id' => 'Изображение', |
||
42 | 'description' => 'Описание', |
||
43 | 'options_inherit' => 'Наследовать набор свойств', |
||
44 | 'options' => 'Свойства товаров', |
||
45 | ]; |
||
46 | public static $forms = [ |
||
47 | 'manager' => [ |
||
48 | 'map' => [ |
||
49 | ['name', 'alias'], |
||
50 | ['parent_id', 'image_file_id'], |
||
51 | ['viewer', 'template'], |
||
52 | ['options_inherit'], |
||
53 | ['options'], |
||
54 | ['description'] |
||
55 | ] |
||
56 | ] |
||
57 | ]; |
||
58 | |||
59 | public static function indexes() { |
||
75 | |||
76 | public static function relations() { |
||
107 | |||
108 | public static $dataManagers = [ |
||
109 | 'manager' => [ |
||
110 | 'name' => 'Категории товаров', |
||
111 | 'cols' => [ |
||
112 | 'name', |
||
113 | 'parent_id', |
||
114 | ], |
||
115 | 'sortMode' => true |
||
116 | ] |
||
117 | ]; |
||
118 | |||
119 | View Code Duplication | public function getRoot() { |
|
129 | |||
130 | public function beforeSave() { |
||
136 | |||
137 | public function beforeDelete() { |
||
142 | |||
143 | View Code Duplication | public function resolveTemplate() { |
|
152 | |||
153 | View Code Duplication | public function resolveViewer() { |
|
162 | } |