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 DeliveryFieldLink extends \Model |
|
| 15 | { |
||
| 16 | static $cols = [ |
||
|
|
|||
| 17 | 'delivery_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'delivery'], |
||
| 18 | 'delivery_field_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'field'], |
||
| 19 | 'weight' => ['type' => 'number'], |
||
| 20 | 'date_create' => ['type' => 'dateTime'] |
||
| 21 | ]; |
||
| 22 | static $dataManagers = [ |
||
| 23 | 'manager' => [ |
||
| 24 | 'name' => 'Поля для доставки', |
||
| 25 | 'cols' => ['delivery_id', 'delivery_field_id', 'date_create'], |
||
| 26 | //'sortMode' => true |
||
| 27 | ] |
||
| 28 | ]; |
||
| 29 | static $forms = [ |
||
| 30 | 'manager' => [ |
||
| 31 | 'map' => [ |
||
| 32 | ['delivery_id', 'delivery_field_id'], |
||
| 33 | ] |
||
| 34 | ] |
||
| 35 | ]; |
||
| 36 | |||
| 37 | static function relations() |
||
| 50 | |||
| 51 | } |
||
| 52 |
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.