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 |
||
17 | class Jetpack_Sync_Debug_Helper { |
||
18 | const API_BASE = 'jetpack_debugger_api_base'; |
||
19 | const LAST_SYNC_ERROR = 'jetpack_debugger_last_sync_error'; |
||
20 | |||
21 | /** |
||
22 | * Saved error |
||
23 | * |
||
24 | * @var boolean |
||
25 | */ |
||
26 | public static $saved_error = false; |
||
27 | |||
28 | /** |
||
29 | * Init hooks |
||
30 | * |
||
31 | * @return void |
||
32 | */ |
||
33 | public static function init() { |
||
39 | |||
40 | /** |
||
41 | * Deactivation hook |
||
42 | */ |
||
43 | public static function deactivate() { |
||
47 | |||
48 | /** |
||
49 | * Pre send |
||
50 | * |
||
51 | * @param array $data The action buffer. |
||
52 | * @param string $codec_name The codec name used to encode the data. |
||
53 | * @param double $sent_timestamp The current time. |
||
54 | * @param string $queue_id The queue used to send ('sync' or 'full_sync'). |
||
55 | * @return array |
||
56 | */ |
||
57 | public static function pre_send( $data, $codec_name, $sent_timestamp, $queue_id ) { |
||
73 | |||
74 | /** |
||
75 | * Pre send |
||
76 | * |
||
77 | * @param array $data The action buffer. |
||
78 | * @param string $codec_name The codec name used to encode the data. |
||
79 | * @param double $sent_timestamp The current time. |
||
80 | * @param string $queue_id The queue used to send ('sync' or 'full_sync'). |
||
81 | * @return array |
||
82 | */ |
||
83 | public static function store_sync_error( $data, $codec_name, $sent_timestamp, $queue_id ) { |
||
108 | |||
109 | /** |
||
110 | * Whitelist synced options |
||
111 | * |
||
112 | * @param array $options options. |
||
113 | * @return array |
||
114 | */ |
||
115 | public static function whitelist_options( $options ) { |
||
124 | |||
125 | } |
||
126 | |||
127 |