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 |
||
| 25 | class Catalog extends \Model { |
||
| 26 | static $cols = [ |
||
|
|
|||
| 27 | 'name' => ['type' => 'text'], |
||
| 28 | 'weight' => ['type' => 'number'], |
||
| 29 | 'parent_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'parent', 'extraValues' => ['0' => 'Нет родителя']], |
||
| 30 | 'icon_file_id' => ['type' => 'image'], |
||
| 31 | 'items_count' => ['type' => 'number'], |
||
| 32 | 'childsMgr' => ['type' => 'dataManager', 'relation' => 'childs'], |
||
| 33 | 'categoriesMgr' => ['type' => 'dataManager', 'relation' => 'categories'], |
||
| 34 | ]; |
||
| 35 | static $labels = [ |
||
| 36 | 'name' => 'Название', |
||
| 37 | 'weight' => 'Вес соритровки', |
||
| 38 | 'parent_id' => 'Родитель', |
||
| 39 | 'icon_file_id' => 'Иконка', |
||
| 40 | 'childsMgr' => 'Дочерние каталоги', |
||
| 41 | 'categoriesMgr' => 'Категории товаров', |
||
| 42 | ]; |
||
| 43 | static $dataManagers = [ |
||
| 44 | 'manager' => [ |
||
| 45 | 'filters' => ['name', 'parent_id'], |
||
| 46 | 'cols' => ['name', 'icon_file_id', 'childsMgr', 'categoriesMgr'], |
||
| 47 | 'sortMode' => true |
||
| 48 | ] |
||
| 49 | ]; |
||
| 50 | static $forms = [ |
||
| 51 | 'manager' => [ |
||
| 52 | 'map' => [ |
||
| 53 | ['name', 'icon_file_id'], |
||
| 54 | ['categoriesMgr'], |
||
| 55 | ['childsMgr'], |
||
| 56 | |||
| 57 | ] |
||
| 58 | ] |
||
| 59 | ]; |
||
| 60 | |||
| 61 | public function calcItemsCount($save = true) { |
||
| 74 | |||
| 75 | View Code Duplication | static function relations() { |
|
| 97 | } |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.