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 | 'network_name' => array( 'Jetpack', 'network_name' ), |
||
| 9 | ); |
||
| 10 | |||
| 11 | static $sync = array(); |
||
| 12 | |||
| 13 | static function sync() { |
||
| 16 | |||
| 17 | View Code Duplication | static function sync_sometimes() { |
|
| 31 | |||
| 32 | View Code Duplication | static function sync_all( $values = null, $check_sum = null ) { |
|
| 42 | |||
| 43 | static function get_check_sum( $values = null ) { |
||
| 49 | |||
| 50 | static function get_query_string( $values ) { |
||
| 53 | |||
| 54 | View Code Duplication | static function values( $sync = array() ) { |
|
| 63 | |||
| 64 | static function get_function_to_sync() { |
||
| 67 | |||
| 68 | static function get( $function ) { |
||
| 71 | |||
| 72 | } |
||
| 73 | |||
| 78 |
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.