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