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 |
||
| 3 | class Jetpack_Options_Sync { |
||
| 4 | |||
| 5 | static $options_to_sync = array(); |
||
|
|
|||
| 6 | |||
| 7 | static $sync = array(); |
||
| 8 | static $delete = array(); |
||
| 9 | |||
| 10 | static function init() { |
||
| 16 | |||
| 17 | static function init_option( $option ) { |
||
| 22 | |||
| 23 | static function delete_option( $option ) { |
||
| 26 | |||
| 27 | View Code Duplication | static function update_option() { |
|
| 36 | |||
| 37 | static function add_option( $option ) { |
||
| 40 | |||
| 41 | static function options_to_delete() { |
||
| 44 | |||
| 45 | static function options_to_sync() { |
||
| 48 | } |
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.