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 |
||
| 4 | class Jetpack_Sync_Options { |
||
| 5 | |||
| 6 | static $options = array( |
||
|
|
|||
| 7 | 'blogname', |
||
| 8 | ); |
||
| 9 | |||
| 10 | static $sync = array(); |
||
| 11 | static $delete = array(); |
||
| 12 | |||
| 13 | static function init() { |
||
| 18 | |||
| 19 | static function register( $option ) { |
||
| 24 | |||
| 25 | static function add_option( $option ) { |
||
| 28 | |||
| 29 | View Code Duplication | static function update_option() { |
|
| 38 | |||
| 39 | static function delete_option( $option ) { |
||
| 42 | |||
| 43 | static function sync() { |
||
| 46 | |||
| 47 | static function sync_sometimes() { |
||
| 62 | |||
| 63 | static function sync_all( $values = null, $check_sum = null ) { |
||
| 73 | |||
| 74 | static function options_to_sync() { |
||
| 77 | |||
| 78 | static function get_check_sum( $values ) { |
||
| 81 | |||
| 82 | static function get_query_string( $values ) { |
||
| 85 | |||
| 86 | static function values( $sync = array() ) { |
||
| 95 | |||
| 96 | static function get_options_to_sync() { |
||
| 99 | |||
| 100 | static function sync_delete() { |
||
| 103 | |||
| 104 | static function get( $constant ) { |
||
| 107 | } |
||
| 108 |
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.