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 Stage extends \Model |
|
| 15 | { |
||
| 16 | public static $objectName = 'Этап наполнения корзины'; |
||
| 17 | public static $cols = [ |
||
| 18 | 'sum' => ['type' => 'decimal'], |
||
| 19 | 'currency_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'currency'], |
||
| 20 | 'type' => ['type' => 'select', 'source' => 'array', 'sourceArray' => ['discount' => 'Скидка']], |
||
| 21 | 'value' => ['type' => 'text'], |
||
| 22 | 'group' => ['type' => 'text'] |
||
| 23 | ]; |
||
| 24 | public static $labels = [ |
||
| 25 | 'sum' => 'Сумма', |
||
| 26 | 'type' => 'Тип', |
||
| 27 | 'group' => 'Группа', |
||
| 28 | 'currency_id' => 'Валюта', |
||
| 29 | 'value' => 'Значение' |
||
| 30 | ]; |
||
| 31 | public static $dataManagers = [ |
||
| 32 | 'manager' => [ |
||
| 33 | 'cols' => ['sum', 'currency_id', 'type', 'value', 'group'] |
||
| 34 | ] |
||
| 35 | ]; |
||
| 36 | public static $forms = [ |
||
| 37 | 'manager' => [ |
||
| 38 | 'map' => [ |
||
| 39 | ['sum', 'currency_id'], |
||
| 40 | ['type', 'value', 'group'] |
||
| 41 | ] |
||
| 42 | ] |
||
| 43 | ]; |
||
| 44 | |||
| 45 | public static function relations() |
||
| 54 | |||
| 55 | } |
||
| 56 |