| Conditions | 16 |
| Paths | 32 |
| Total Lines | 77 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 12 | ||
| Bugs | 3 | 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 |
||
| 13 | static function init() { |
||
| 14 | |||
| 15 | // On jetpack authorization, schedule a full sync |
||
| 16 | add_action( 'jetpack_client_authorized', array( __CLASS__, 'schedule_full_sync' ) ); |
||
| 17 | |||
| 18 | // cron hooks |
||
| 19 | add_action( 'jetpack_sync_send_db_checksum', array( __CLASS__, 'send_db_checksum' ) ); |
||
| 20 | add_action( 'jetpack_sync_full', array( __CLASS__, 'do_full_sync' ) ); |
||
| 21 | add_action( 'jetpack_sync_send_pending_data', array( __CLASS__, 'do_send_pending_data' ) ); |
||
| 22 | |||
| 23 | $prevent_sync_loading = |
||
| 24 | ( !Jetpack::is_active() || Jetpack::is_development_mode() || Jetpack::is_staging_site() ) |
||
| 25 | && |
||
| 26 | !defined( 'PHPUNIT_JETPACK_TESTSUITE' ); |
||
| 27 | |||
| 28 | if ( ! $prevent_sync_loading && ! wp_next_scheduled ( 'jetpack_sync_send_db_checksum' ) ) { |
||
| 29 | // Schedule a job to send DB checksums once an hour |
||
| 30 | wp_schedule_event( time(), 'hourly', 'jetpack_sync_send_db_checksum' ); |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Fires on every request before default loading sync listener code. |
||
| 35 | * Return false to not load sync listener code that monitors common |
||
| 36 | * WP actions to be serialized. |
||
| 37 | * |
||
| 38 | * By default this returns true for non-GET-requests, or requests where the |
||
| 39 | * user is logged-in. |
||
| 40 | * |
||
| 41 | * @since 4.2.0 |
||
| 42 | * |
||
| 43 | * @param bool should we load sync listener code for this request |
||
| 44 | */ |
||
| 45 | if ( !$prevent_sync_loading && apply_filters( 'jetpack_sync_listener_should_load', |
||
| 46 | ( |
||
| 47 | $_SERVER['REQUEST_METHOD'] !== 'GET' |
||
| 48 | || |
||
| 49 | is_user_logged_in() |
||
| 50 | || |
||
| 51 | defined( 'PHPUNIT_JETPACK_TESTSUITE' ) |
||
| 52 | || |
||
| 53 | is_admin() |
||
| 54 | ) |
||
| 55 | ) ) { |
||
| 56 | self::initialize_listener(); |
||
| 57 | } |
||
| 58 | |||
| 59 | // Sync connected user role changes to .com |
||
| 60 | require_once dirname( __FILE__ ) . '/class.jetpack-sync-users.php'; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Fires on every request before default loading sync sender code. |
||
| 64 | * Return false to not load sync sender code that serializes pending |
||
| 65 | * data and sends it to WPCOM for processing. |
||
| 66 | * |
||
| 67 | * By default this returns true for POST requests, admin requests, or requests |
||
| 68 | * by users who can manage_options. |
||
| 69 | * |
||
| 70 | * @since 4.2.0 |
||
| 71 | * |
||
| 72 | * @param bool should we load sync sender code for this request |
||
| 73 | */ |
||
| 74 | if ( !$prevent_sync_loading && apply_filters( 'jetpack_sync_sender_should_load', |
||
| 75 | ( |
||
| 76 | $_SERVER['REQUEST_METHOD'] === 'POST' |
||
| 77 | || |
||
| 78 | current_user_can( 'manage_options' ) |
||
| 79 | || |
||
| 80 | is_admin() |
||
| 81 | || |
||
| 82 | defined( 'PHPUNIT_JETPACK_TESTSUITE' ) |
||
| 83 | ) |
||
| 84 | ) ) { |
||
| 85 | self::initialize_sender(); |
||
| 86 | add_action( 'shutdown', array( self::$sender, 'do_sync' ) ); |
||
| 87 | } |
||
| 88 | |||
| 89 | } |
||
| 90 | |||
| 153 |
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.