Conditions | 14 |
Paths | 448 |
Total Lines | 87 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
37 | function start( $modules = null ) { |
||
38 | $was_already_running = $this->is_started() && ! $this->is_finished(); |
||
39 | |||
40 | // remove all evidence of previous full sync items and status |
||
41 | $this->reset_data(); |
||
42 | |||
43 | if ( $was_already_running ) { |
||
44 | /** |
||
45 | * Fires when a full sync is cancelled. |
||
46 | * |
||
47 | * @since 4.2.0 |
||
48 | */ |
||
49 | do_action( 'jetpack_full_sync_cancelled' ); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Fires when a full sync begins. This action is serialized |
||
54 | * and sent to the server so that it knows a full sync is coming. |
||
55 | * |
||
56 | * @since 4.2.0 |
||
57 | */ |
||
58 | do_action( 'jetpack_full_sync_start' ); |
||
59 | $this->update_status_option( 'started', time() ); |
||
60 | |||
61 | // configure modules |
||
62 | if ( ! is_array( $modules ) ) { |
||
63 | $modules = array(); |
||
64 | } |
||
65 | |||
66 | // by default, all modules are fully enabled |
||
67 | if ( count( $modules ) === 0 ) { |
||
68 | $default_module_config = true; |
||
69 | } else { |
||
70 | $default_module_config = false; |
||
71 | } |
||
72 | |||
73 | // set default configuration, calculate totals, and save configuration if totals > 0 |
||
74 | foreach ( Jetpack_Sync_Modules::get_modules() as $module ) { |
||
75 | $module_name = $module->name(); |
||
76 | if ( ! isset( $modules[ $module_name ] ) ) { |
||
77 | $modules[ $module_name ] = $default_module_config; |
||
78 | } |
||
79 | |||
80 | // check if this module is enabled |
||
81 | if ( ! ( $module_config = $modules[ $module_name ] ) ) { |
||
82 | continue; |
||
83 | } |
||
84 | |||
85 | $total_items = $module->estimate_full_sync_actions( $module_config ); |
||
86 | |||
87 | if ( ! is_null( $total_items ) && $total_items > 0 ) { |
||
88 | $this->update_status_option( "{$module_name}_total", $total_items ); |
||
89 | $this->update_status_option( "{$module_name}_config", $module_config ); |
||
90 | } |
||
91 | } |
||
92 | |||
93 | foreach ( Jetpack_Sync_Modules::get_modules() as $module ) { |
||
94 | $module_name = $module->name(); |
||
95 | $module_config = $modules[ $module_name ]; |
||
96 | |||
97 | // check if this module is enabled |
||
98 | if ( ! $module_config ) { |
||
99 | continue; |
||
100 | } |
||
101 | |||
102 | $items_enqueued = $module->enqueue_full_sync_actions( $module_config ); |
||
103 | |||
104 | if ( ! is_null( $items_enqueued ) && $items_enqueued > 0 ) { |
||
105 | $this->update_status_option( "{$module_name}_queued", $items_enqueued ); |
||
106 | } |
||
107 | } |
||
108 | |||
109 | $this->update_status_option( 'queue_finished', time() ); |
||
110 | |||
111 | $store = new Jetpack_Sync_WP_Replicastore(); |
||
112 | |||
113 | /** |
||
114 | * Fires when a full sync ends. This action is serialized |
||
115 | * and sent to the server with checksums so that we can confirm the |
||
116 | * sync was successful. |
||
117 | * |
||
118 | * @since 4.2.0 |
||
119 | */ |
||
120 | do_action( 'jetpack_full_sync_end', $store->checksum_all() ); |
||
121 | |||
122 | return true; |
||
123 | } |
||
124 | |||
242 |