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 |
||
| 16 | View Code Duplication | class Change extends \Model { |
|
| 17 | |||
| 18 | static $logging = false; |
||
|
|
|||
| 19 | static $cols = [ |
||
| 20 | 'activity_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'activity'], |
||
| 21 | 'col' => ['type' => 'text'], |
||
| 22 | 'old' => ['type' => 'textarea'], |
||
| 23 | 'new' => ['type' => 'textarea'], |
||
| 24 | 'date_create' => ['type' => 'dateTime'] |
||
| 25 | ]; |
||
| 26 | |||
| 27 | static function relations() { |
||
| 35 | |||
| 36 | } |
||
| 37 |
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.