| Conditions | 11 |
| Paths | 112 |
| Total Lines | 53 |
| Code Lines | 27 |
| Lines | 4 |
| Ratio | 7.55 % |
| Changes | 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 |
||
| 6 | static function start( $modules = null ) { |
||
| 7 | // todo detect if config already set and/or sync already in progress |
||
|
|
|||
| 8 | |||
| 9 | $config = array(); |
||
| 10 | |||
| 11 | if ( ! is_array( $modules ) ) { |
||
| 12 | $modules = array(); |
||
| 13 | } |
||
| 14 | |||
| 15 | View Code Duplication | if ( isset( $modules['users'] ) && 'initial' === $modules['users'] ) { |
|
| 16 | $user_module = Jetpack_Sync_Modules::get_module( 'users' ); |
||
| 17 | $modules['users'] = $user_module->get_initial_sync_user_config(); |
||
| 18 | } |
||
| 19 | |||
| 20 | // by default, all modules are fully enabled |
||
| 21 | if ( count( $modules ) === 0 ) { |
||
| 22 | $default_module_config = true; |
||
| 23 | } else { |
||
| 24 | $default_module_config = false; |
||
| 25 | } |
||
| 26 | |||
| 27 | // set default configuration, calculate totals, and save configuration if totals > 0 |
||
| 28 | foreach ( Jetpack_Sync_Modules::get_modules() as $module ) { |
||
| 29 | $module_name = $module->name(); |
||
| 30 | if ( ! isset( $modules[ $module_name ] ) ) { |
||
| 31 | $modules[ $module_name ] = $default_module_config; |
||
| 32 | } |
||
| 33 | |||
| 34 | // check if this module is enabled |
||
| 35 | if ( ! ( $module_config = $modules[ $module_name ] ) ) { |
||
| 36 | continue; |
||
| 37 | } |
||
| 38 | |||
| 39 | $total_items = $module->estimate_full_sync_actions( $module_config ); |
||
| 40 | |||
| 41 | if ( ! is_null( $total_items ) && $total_items > 0 ) { |
||
| 42 | $config[ $module_name ] = array( |
||
| 43 | 'total' => $total_items, |
||
| 44 | 'config' => $module_config, |
||
| 45 | ); |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | self::set_config( $config ); |
||
| 50 | |||
| 51 | // now let's set an initial status |
||
| 52 | $status = array(); |
||
| 53 | foreach( $config as $module => $params ) { |
||
| 54 | $status[ $module ] = array(); |
||
| 55 | } |
||
| 56 | |||
| 57 | self::set_status( $status ); |
||
| 58 | } |
||
| 59 | |||
| 176 | } |