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_Sync_Functions { |
||
| 4 | |||
| 5 | static $functions = array( |
||
|
|
|||
| 6 | 'wp_version' => array( 'Jetpack', 'get_wp_version' ), |
||
| 7 | 'wp_max_upload_size' => 'wp_max_upload_size', |
||
| 8 | 'featured_images_enabled' => array( 'Jetpack', 'featured_images_enabled' ), |
||
| 9 | ); |
||
| 10 | |||
| 11 | static $multi_site_functions = array( |
||
| 12 | 'network_name' => array( 'Jetpack', 'network_name' ), |
||
| 13 | 'network_allow_new_registrations' => array( 'Jetpack', 'network_allow_new_registrations' ), |
||
| 14 | 'network_add_new_users' => array( 'Jetpack', 'network_add_new_users' ), |
||
| 15 | 'network_site_upload_space' => array( 'Jetpack', 'network_site_upload_space' ), |
||
| 16 | 'network_upload_file_types' => array( 'Jetpack', 'network_upload_file_types' ), |
||
| 17 | 'network_enable_administration_menus' => array( 'Jetpack', 'network_enable_administration_menus' ), |
||
| 18 | ); |
||
| 19 | |||
| 20 | static $sync = array(); |
||
| 21 | |||
| 22 | static function init() { |
||
| 27 | |||
| 28 | static function sync() { |
||
| 31 | |||
| 32 | static function register( $key, $function ) { |
||
| 35 | |||
| 36 | static function trigger_sync( $key ) { |
||
| 39 | |||
| 40 | View Code Duplication | static function sync_sometimes() { |
|
| 55 | |||
| 56 | View Code Duplication | static function sync_all( $values = null, $check_sum = null ) { |
|
| 67 | |||
| 68 | static function get_check_sum( $values = null ) { |
||
| 75 | |||
| 76 | static function get_query_string( $values ) { |
||
| 79 | |||
| 80 | static function values( $sync = array() ) { |
||
| 94 | |||
| 95 | static function get_function_to_sync() { |
||
| 98 | |||
| 99 | static function get( $key ) { |
||
| 108 | |||
| 109 | } |
||
| 110 | |||
| 115 |
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.