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 |
||
| 5 | class Jetpack_Sync_Module_Callables extends Jetpack_Sync_Module { |
||
| 6 | const CALLABLES_CHECKSUM_OPTION_NAME = 'jetpack_callables_sync_checksum'; |
||
| 7 | const CALLABLES_AWAIT_TRANSIENT_NAME = 'jetpack_sync_callables_await'; |
||
| 8 | |||
| 9 | private $callable_whitelist; |
||
| 10 | |||
| 11 | public function name() { |
||
| 14 | |||
| 15 | public function set_defaults() { |
||
| 22 | |||
| 23 | public function init_listeners( $callable ) { |
||
| 24 | add_action( 'jetpack_sync_callable', $callable, 10, 2 ); |
||
| 25 | |||
| 26 | // full sync |
||
| 27 | add_action( 'jetpack_full_sync_callables', $callable ); |
||
| 28 | |||
| 29 | // always send change to active modules right away |
||
| 30 | add_action( 'update_option_jetpack_active_modules', array( $this, 'unlock_sync_callable' ) ); |
||
| 31 | |||
| 32 | // get_plugins and wp_version |
||
| 33 | // gets fired when new code gets installed, updates etc. |
||
| 34 | add_action( 'upgrader_process_complete', array( $this, 'unlock_sync_callable' ) ); |
||
| 35 | } |
||
| 36 | |||
| 37 | public function init_full_sync_listeners( $callable ) { |
||
| 38 | add_action( 'jetpack_full_sync_callables', $callable ); |
||
| 39 | } |
||
| 40 | |||
| 41 | public function init_before_send() { |
||
| 42 | add_action( 'jetpack_sync_before_send_queue_sync', array( $this, 'maybe_sync_callables' ) ); |
||
| 43 | |||
| 44 | // full sync |
||
| 45 | add_filter( 'jetpack_sync_before_send_jetpack_full_sync_callables', array( $this, 'expand_callables' ) ); |
||
| 46 | } |
||
| 47 | |||
| 48 | public function reset_data() { |
||
| 52 | |||
| 53 | function set_callable_whitelist( $callables ) { |
||
| 56 | |||
| 57 | function get_callable_whitelist() { |
||
| 60 | |||
| 61 | public function get_all_callables() { |
||
| 62 | // get_all_callables should run as the master user always. |
||
| 63 | $current_user_id = get_current_user_id(); |
||
| 73 | |||
| 74 | private function get_callable( $callable ) { |
||
| 77 | |||
| 78 | public function enqueue_full_sync_actions() { |
||
| 90 | |||
| 91 | public function get_full_sync_actions() { |
||
| 94 | |||
| 95 | public function unlock_sync_callable() { |
||
| 98 | |||
| 99 | View Code Duplication | public function maybe_sync_callables() { |
|
| 135 | |||
| 136 | public function expand_callables( $args ) { |
||
| 143 | } |
||
| 144 |
This check looks for access to properties that are not accessible from the current context.
If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.