Conditions | 7 |
Paths | 8 |
Total Lines | 62 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
43 | function receive( $data, $token = null, $sent_timestamp = null, $queue_id = null ) { |
||
44 | $start_time = microtime( true ); |
||
45 | if ( ! is_array( $data ) ) { |
||
46 | return new WP_Error( 'action_decoder_error', 'Events must be an array' ); |
||
47 | } |
||
48 | |||
49 | if ( $token && ! $this->attempt_request_lock( $token->blog_id ) ) { |
||
50 | /** |
||
51 | * Fires when the server receives two concurrent requests from the same blog |
||
52 | * |
||
53 | * @since 4.2.0 |
||
54 | * |
||
55 | * @param token The token object of the misbehaving site |
||
56 | */ |
||
57 | do_action( 'jetpack_sync_multi_request_fail', $token ); |
||
58 | |||
59 | return new WP_Error( 'concurrent_request_error', 'There is another request running for the same blog ID' ); |
||
60 | } |
||
61 | |||
62 | $events = wp_unslash( array_map( array( $this->codec, 'decode' ), $data ) ); |
||
63 | $events_processed = array(); |
||
64 | |||
65 | /** |
||
66 | * Fires when an array of actions are received from a remote Jetpack site |
||
67 | * |
||
68 | * @since 4.2.0 |
||
69 | * |
||
70 | * @param array Array of actions received from the remote site |
||
71 | */ |
||
72 | do_action( 'jetpack_sync_remote_actions', $events, $token ); |
||
73 | |||
74 | foreach ( $events as $key => $event ) { |
||
75 | list( $action_name, $args, $user_id, $timestamp ) = $event; |
||
76 | |||
77 | /** |
||
78 | * Fires when an action is received from a remote Jetpack site |
||
79 | * |
||
80 | * @since 4.2.0 |
||
81 | * |
||
82 | * @param string $action_name The name of the action executed on the remote site |
||
83 | * @param array $args The arguments passed to the action |
||
84 | * @param int $user_id The external_user_id who did the action |
||
85 | * @param double $timestamp Timestamp (in seconds) when the action occurred |
||
86 | * @param double $sent_timestamp Timestamp (in seconds) when the action was transmitted |
||
87 | * @param string $queue_id ID of the queue from which the event was sent (sync or full_sync) |
||
88 | * @param array $token The auth token used to invoke the API |
||
89 | */ |
||
90 | do_action( 'jetpack_sync_remote_action', $action_name, $args, $user_id, $timestamp, $sent_timestamp, $queue_id, $token ); |
||
91 | |||
92 | $events_processed[] = $key; |
||
93 | |||
94 | if ( microtime( true ) - $start_time > self::MAX_TIME_PER_REQUEST_IN_SECONDS ) { |
||
95 | break; |
||
96 | } |
||
97 | } |
||
98 | |||
99 | if ( $token ) { |
||
100 | $this->remove_request_lock( $token->blog_id ); |
||
101 | } |
||
102 | |||
103 | return $events_processed; |
||
104 | } |
||
105 | } |
||
106 |