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 Param extends \Model { |
|
| 15 | |||
| 16 | public static $objectName = 'Параметр товара'; |
||
| 17 | public static $labels = [ |
||
| 18 | 'item_offer_option_id' => 'Параметр предложения', |
||
| 19 | 'item_offer_id' => 'Предложение', |
||
| 20 | 'value' => 'Значение', |
||
| 21 | ]; |
||
| 22 | public static $cols = [ |
||
| 23 | //Основные параметры |
||
| 24 | 'item_offer_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'offer'], |
||
| 25 | 'item_offer_option_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'option', 'onChange' => 'reloadForm'], |
||
| 26 | 'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType'], |
||
| 27 | //Системные |
||
| 28 | 'date_create' => ['type' => 'dateTime'] |
||
| 29 | ]; |
||
| 30 | |||
| 31 | public static function indexes() { |
||
| 54 | |||
| 55 | public function realType() { |
||
| 70 | |||
| 71 | public static $dataManagers = [ |
||
| 72 | |||
| 73 | 'manager' => [ |
||
| 74 | 'name' => 'Параметры предложения', |
||
| 75 | 'cols' => [ |
||
| 76 | 'item_offer_option_id', |
||
| 77 | 'item_offer_id', |
||
| 78 | 'value', |
||
| 79 | ], |
||
| 80 | ], |
||
| 81 | ]; |
||
| 82 | public static $forms = [ |
||
| 83 | 'manager' => [ |
||
| 84 | 'map' => [ |
||
| 85 | ['item_offer_id', 'item_offer_option_id'], |
||
| 86 | ['value'] |
||
| 87 | ] |
||
| 88 | ]]; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Return final param value |
||
| 92 | * |
||
| 93 | * @param string $default |
||
| 94 | * @return string |
||
| 95 | */ |
||
| 96 | public function valueText($default = '') { |
||
| 104 | |||
| 105 | public static function relations() { |
||
| 125 | } |