| Conditions | 11 |
| Paths | 17 |
| Total Lines | 89 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 15 | static function init() { |
||
| 16 | |||
| 17 | // Add a custom "every minute" cron schedule |
||
| 18 | add_filter( 'cron_schedules', array( __CLASS__, 'minute_cron_schedule' ) ); |
||
| 19 | |||
| 20 | // On jetpack authorization, schedule a full sync |
||
| 21 | add_action( 'jetpack_client_authorized', array( __CLASS__, 'schedule_full_sync' ) ); |
||
| 22 | |||
| 23 | // When imports are finished, schedule a full sync |
||
| 24 | add_action( 'import_end', array( __CLASS__, 'schedule_full_sync' ) ); |
||
| 25 | |||
| 26 | // When importing via cron, do not sync |
||
| 27 | add_action( 'wp_cron_importer_hook', array( __CLASS__, 'set_is_importing_true' ), 1 ); |
||
| 28 | |||
| 29 | // Sync connected user role changes to .com |
||
| 30 | require_once dirname( __FILE__ ) . '/class.jetpack-sync-users.php'; |
||
| 31 | |||
| 32 | // everything below this point should only happen if we're a valid sync site |
||
| 33 | if ( ! self::sync_allowed() ) { |
||
| 34 | return; |
||
| 35 | } |
||
| 36 | |||
| 37 | // cron hooks |
||
| 38 | add_action( 'jetpack_sync_send_db_checksum', array( __CLASS__, 'send_db_checksum' ) ); |
||
| 39 | add_action( 'jetpack_sync_full', array( __CLASS__, 'do_full_sync' ), 10, 1 ); |
||
| 40 | add_action( 'jetpack_sync_cron', array( __CLASS__, 'do_cron_sync' ) ); |
||
| 41 | |||
| 42 | if ( ! wp_next_scheduled( 'jetpack_sync_send_db_checksum' ) ) { |
||
| 43 | // Schedule a job to send DB checksums once an hour |
||
| 44 | wp_schedule_event( time(), 'hourly', 'jetpack_sync_send_db_checksum' ); |
||
| 45 | } |
||
| 46 | |||
| 47 | if ( ! wp_next_scheduled( 'jetpack_sync_cron' ) ) { |
||
| 48 | // Schedule a job to send pending queue items once a minute |
||
| 49 | wp_schedule_event( time(), '1min', 'jetpack_sync_cron' ); |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Fires on every request before default loading sync listener code. |
||
| 54 | * Return false to not load sync listener code that monitors common |
||
| 55 | * WP actions to be serialized. |
||
| 56 | * |
||
| 57 | * By default this returns true for non-GET-requests, or requests where the |
||
| 58 | * user is logged-in. |
||
| 59 | * |
||
| 60 | * @since 4.2.0 |
||
| 61 | * |
||
| 62 | * @param bool should we load sync listener code for this request |
||
| 63 | */ |
||
| 64 | if ( apply_filters( 'jetpack_sync_listener_should_load', |
||
| 65 | ( |
||
| 66 | 'GET' !== $_SERVER['REQUEST_METHOD'] |
||
| 67 | || |
||
| 68 | is_user_logged_in() |
||
| 69 | || |
||
| 70 | defined( 'PHPUNIT_JETPACK_TESTSUITE' ) |
||
| 71 | ) |
||
| 72 | ) ) { |
||
| 73 | self::initialize_listener(); |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Fires on every request before default loading sync sender code. |
||
| 78 | * Return false to not load sync sender code that serializes pending |
||
| 79 | * data and sends it to WPCOM for processing. |
||
| 80 | * |
||
| 81 | * By default this returns true for POST requests, admin requests, or requests |
||
| 82 | * by users who can manage_options. |
||
| 83 | * |
||
| 84 | * @since 4.2.0 |
||
| 85 | * |
||
| 86 | * @param bool should we load sync sender code for this request |
||
| 87 | */ |
||
| 88 | if ( apply_filters( 'jetpack_sync_sender_should_load', |
||
| 89 | ( |
||
| 90 | 'POST' === $_SERVER['REQUEST_METHOD'] |
||
| 91 | || |
||
| 92 | current_user_can( 'manage_options' ) |
||
| 93 | || |
||
| 94 | is_admin() |
||
| 95 | || |
||
| 96 | defined( 'PHPUNIT_JETPACK_TESTSUITE' ) |
||
| 97 | ) |
||
| 98 | ) ) { |
||
| 99 | self::initialize_sender(); |
||
| 100 | add_action( 'shutdown', array( self::$sender, 'do_sync' ) ); |
||
| 101 | } |
||
| 102 | |||
| 103 | } |
||
| 104 | |||
| 258 |
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.