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 |
||
8 | class JetpackTracking { |
||
9 | static $product_name = 'jetpack'; |
||
|
|||
10 | |||
11 | static function track_jetpack_usage() { |
||
23 | |||
24 | View Code Duplication | static function enqueue_tracks_scripts() { |
|
25 | wp_enqueue_script( 'jptracks', plugins_url( '_inc/lib/tracks/tracks-ajax.js', JETPACK__PLUGIN_FILE ), array(), JETPACK__VERSION, true ); |
||
26 | wp_localize_script( 'jptracks', 'jpTracksAJAX', array( |
||
27 | 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
||
28 | 'jpTracksAJAX_nonce' => wp_create_nonce( 'jp-tracks-ajax-nonce' ), |
||
29 | ) ); |
||
30 | } |
||
31 | |||
32 | /* User has linked their account */ |
||
33 | static function track_user_linked() { |
||
50 | |||
51 | /* Activated module */ |
||
52 | static function track_activate_module( $module ) { |
||
55 | |||
56 | /* Deactivated module */ |
||
57 | static function track_deactivate_module( $module ) { |
||
60 | |||
61 | static function record_user_event( $event_type, $data= array(), $user = null ) { |
||
83 | } |
||
84 | |||
86 |
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.