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 Country extends \Model |
|
| 15 | { |
||
| 16 | public static $objectName = 'Страна'; |
||
| 17 | public static $labels = [ |
||
| 18 | 'name' => 'Название', |
||
| 19 | 'city' => 'Город', |
||
| 20 | 'date_create' => 'Дата создания', |
||
| 21 | ]; |
||
| 22 | public static $cols = [ |
||
| 23 | 'name' => ['type' => 'text'], |
||
| 24 | 'city' => ['type' => 'dataManager', 'relation' => 'citys'], |
||
| 25 | 'date_create' => ['type' => 'dateTime'], |
||
| 26 | ]; |
||
| 27 | public static $dataManagers = [ |
||
| 28 | 'manager' => [ |
||
| 29 | 'cols' => ['name', 'city', 'date_create'] |
||
| 30 | ] |
||
| 31 | ]; |
||
| 32 | public static $forms = [ |
||
| 33 | 'manager' => [ |
||
| 34 | 'map' => [ |
||
| 35 | ['name'] |
||
| 36 | ] |
||
| 37 | ] |
||
| 38 | ]; |
||
| 39 | |||
| 40 | public static function relations() |
||
| 50 | |||
| 51 | } |
||
| 52 |