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 Activity extends \Model |
|
15 | { |
||
16 | public static $objectName = 'Activity'; |
||
17 | public static $labels = [ |
||
18 | 'text' => 'Текст', |
||
19 | 'user_id' => 'Пользователь', |
||
20 | 'category_id' => 'Категория', |
||
21 | ]; |
||
22 | public static $cols = [ |
||
23 | 'text' => ['type' => 'text'], |
||
24 | 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
||
25 | 'category_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'category'], |
||
26 | ]; |
||
27 | public static $dataManagers = [ |
||
28 | 'manager' => [ |
||
29 | 'name' => 'Activity', |
||
30 | 'cols' => [ |
||
31 | 'text', 'user_id', 'category_id', 'date_create', |
||
32 | ] |
||
33 | ] |
||
34 | ]; |
||
35 | public static $forms = [ |
||
36 | 'manager' => [ |
||
37 | 'map' => [ |
||
38 | ['text'], |
||
39 | ['user_id', 'category_id'] |
||
40 | ] |
||
41 | ] |
||
42 | ]; |
||
43 | |||
44 | public static function relations() |
||
57 | |||
58 | } |
||
59 |