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 Field extends \Model { |
|
| 15 | |||
| 16 | public static $objectName = 'Поле доставки'; |
||
| 17 | public static $cols = [ |
||
| 18 | //Основные параметры |
||
| 19 | 'name' => ['type' => 'text'], |
||
| 20 | 'type' => ['type' => 'text'], |
||
| 21 | 'userfield' => ['type' => 'text'], |
||
| 22 | 'required' => ['type' => 'bool'], |
||
| 23 | 'save' => ['type' => 'bool'], |
||
| 24 | 'fieldItem'=>['type'=>'dataManager','relation'=>'fieldItems'], |
||
| 25 | //Системные |
||
| 26 | 'date_create' => ['type' => 'dateTime'], |
||
| 27 | ]; |
||
| 28 | public static $labels = [ |
||
| 29 | 'name' => 'Название', |
||
| 30 | 'type' => 'Тип', |
||
| 31 | 'userfield' => 'Связь с данными пользователя', |
||
| 32 | 'required' => 'Обязательно', |
||
| 33 | 'save' => 'Сохраняется', |
||
| 34 | 'fieldItem' => 'Значения для списка', |
||
| 35 | ]; |
||
| 36 | public static $dataManagers = [ |
||
| 37 | 'manager' => [ |
||
| 38 | 'cols' => [ |
||
| 39 | 'name', 'type', 'userfield', 'required','fieldItem', 'save' |
||
| 40 | ], |
||
| 41 | ] |
||
| 42 | ]; |
||
| 43 | public static $forms = [ |
||
| 44 | 'manager' => [ |
||
| 45 | 'map' => [ |
||
| 46 | ['name', 'type'], |
||
| 47 | ['required', 'save'], |
||
| 48 | [ 'userfield'] |
||
| 49 | ] |
||
| 50 | ] |
||
| 51 | ]; |
||
| 52 | |||
| 53 | public static function relations() { |
||
| 62 | |||
| 63 | } |
||
| 64 |