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 | View Code Duplication | class Info extends \Model { |
|
15 | |||
16 | public static $objectName = 'Информация'; |
||
17 | public static $labels = [ |
||
18 | 'name' => 'Название', |
||
19 | 'value' => 'Значение', |
||
20 | 'useradds_field_id' => 'Поле', |
||
21 | 'cart_id' => 'Корзина' |
||
22 | ]; |
||
23 | public static $cols = [ |
||
24 | 'name' => ['type' => 'text'], |
||
25 | 'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType'], |
||
26 | 'cart_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'cart'], |
||
27 | 'useradds_field_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'field'], |
||
28 | //Системные параметры |
||
29 | 'date_create' => ['type' => 'dateTime'], |
||
30 | ]; |
||
31 | public static $dataManagers = [ |
||
32 | 'manager' => [ |
||
33 | 'cols' => [ |
||
34 | 'name', |
||
35 | 'value', |
||
36 | ], |
||
37 | ], |
||
38 | ]; |
||
39 | public static $forms = [ |
||
40 | 'manager' => [ |
||
41 | 'map' => [ |
||
42 | ['name', 'value'], |
||
43 | ['useradds_field_id', 'cart_id'], |
||
44 | ] |
||
45 | ] |
||
46 | ]; |
||
47 | |||
48 | public static function relations() { |
||
60 | |||
61 | public function realType() { |
||
81 | } |
||
82 |