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() |
||
| 55 | |||
| 56 | public function realType() |
||
| 72 | |||
| 73 | public static $dataManagers = [ |
||
| 74 | |||
| 75 | 'manager' => [ |
||
| 76 | 'name' => 'Параметры предложения', |
||
| 77 | 'cols' => [ |
||
| 78 | 'item_offer_option_id', |
||
| 79 | 'item_offer_id', |
||
| 80 | 'value', |
||
| 81 | ], |
||
| 82 | ], |
||
| 83 | ]; |
||
| 84 | public static $forms = [ |
||
| 85 | 'manager' => [ |
||
| 86 | 'map' => [ |
||
| 87 | ['item_offer_id', 'item_offer_option_id'], |
||
| 88 | ['value'] |
||
| 89 | ] |
||
| 90 | ]]; |
||
| 91 | |||
| 92 | function name() |
||
| 96 | |||
| 97 | public function value($default = '') |
||
| 106 | |||
| 107 | public static function relations() |
||
| 128 | |||
| 129 | } |
||
| 130 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.