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 Option extends \Model |
|
| 15 | { |
||
| 16 | public static $objectName = 'Свойство предложения'; |
||
| 17 | public static $cols = [ |
||
| 18 | //Основные параметры |
||
| 19 | 'name' => ['type' => 'text'], |
||
| 20 | 'filter_name' => ['type' => 'text'], |
||
| 21 | 'image_file_id' => ['type' => 'image'], |
||
| 22 | 'code' => ['type' => 'text'], |
||
| 23 | 'type' => ['type' => 'text'], |
||
| 24 | 'postfix' => ['type' => 'text'], |
||
| 25 | 'default_val' => ['type' => 'text'], |
||
| 26 | 'view' => ['type' => 'bool'], |
||
| 27 | 'searchable' => ['type' => 'bool'], |
||
| 28 | //Системные |
||
| 29 | 'weight' => ['type' => 'number'], |
||
| 30 | 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
||
| 31 | 'advance' => ['type' => 'text'], |
||
| 32 | 'date_create' => ['type' => 'dateTime'], |
||
| 33 | //Менеджеры |
||
| 34 | 'item' => ['type' => 'dataManager', 'relation' => 'items'], |
||
| 35 | ]; |
||
| 36 | public static $labels = [ |
||
| 37 | 'name' => 'Название', |
||
| 38 | 'filter_name' => 'Название в фильтре', |
||
| 39 | 'image_file_id' => 'Иконка', |
||
| 40 | 'code' => 'Код', |
||
| 41 | 'type' => 'Тип', |
||
| 42 | 'postfix' => 'Постфикс', |
||
| 43 | 'default_val' => 'Значение по умолчанию', |
||
| 44 | 'view' => 'Отображается', |
||
| 45 | 'searchable' => 'Используется при поиске', |
||
| 46 | 'weight' => 'Вес сортировки', |
||
| 47 | 'advance' => 'Дополнительные параметры', |
||
| 48 | 'user_id' => 'Создатель', |
||
| 49 | 'date_create' => 'Дата создания', |
||
| 50 | 'item' => 'Значения для списка' |
||
| 51 | ]; |
||
| 52 | public static $dataManagers = [ |
||
| 53 | 'manager' => [ |
||
| 54 | 'name' => 'Свойства предложения', |
||
| 55 | 'cols' => [ |
||
| 56 | 'name', 'code', 'type', 'item', 'view', 'searchable', 'user_id', 'date_create' |
||
| 57 | ] |
||
| 58 | ] |
||
| 59 | ]; |
||
| 60 | public static $forms = [ |
||
| 61 | 'manager' => [ |
||
| 62 | 'map' => [ |
||
| 63 | ['name', 'filter_name'], |
||
| 64 | ['code', 'type', 'image_file_id'], |
||
| 65 | ['default_val', 'postfix'], |
||
| 66 | ['view', 'searchable'], |
||
| 67 | ['item'] |
||
| 68 | ] |
||
| 69 | ] |
||
| 70 | ]; |
||
| 71 | |||
| 72 | public static function relations() |
||
| 90 | |||
| 91 | public function beforeSave() |
||
| 97 | |||
| 98 | } |
||
| 99 |