Conditions | 7 |
Paths | 8 |
Total Lines | 71 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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 |
||
42 | function receive( $data, $token = null ) { |
||
43 | $start_time = microtime( true ); |
||
44 | if ( ! is_array( $data ) ) { |
||
45 | return new WP_Error( 'action_decoder_error', 'Events must be an array' ); |
||
46 | } |
||
47 | |||
48 | if ( $token && ! $this->attempt_request_lock( $token->blog_id ) ) { |
||
49 | /** |
||
50 | * Fires when the server receives two concurrent requests from the same blog |
||
51 | * |
||
52 | * @since 4.1 |
||
53 | * |
||
54 | * @param token The token object of the misbehaving site |
||
55 | */ |
||
56 | do_action( "jetpack_sync_multi_request_fail", $token ); |
||
57 | return new WP_Error( 'concurrent_request_error', 'There is another request running for the same blog ID' ); |
||
58 | } |
||
59 | |||
60 | $events = wp_unslash( array_map( array( $this->codec, 'decode' ), $data ) ); |
||
61 | $events_processed = array(); |
||
62 | |||
63 | /** |
||
64 | * Fires when an array of actions are received from a remote Jetpack site |
||
65 | * |
||
66 | * @since 4.1 |
||
67 | * |
||
68 | * @param array Array of actions received from the remote site |
||
69 | */ |
||
70 | do_action( "jetpack_sync_remote_actions", $events, $token ); |
||
71 | |||
72 | foreach ( $events as $key => $event ) { |
||
73 | list( $action_name, $args, $user_id, $timestamp ) = $event; |
||
74 | |||
75 | /** |
||
76 | * Fires when an action is received from a remote Jetpack site |
||
77 | * |
||
78 | * @since 4.1 |
||
79 | * |
||
80 | * @param string $action_name The name of the action executed on the remote site |
||
81 | * @param array $args The arguments passed to the action |
||
82 | * @param int $user_id The external_user_id who did the action |
||
83 | * @param double $timestamp Timestamp (in seconds) when the action occurred |
||
84 | * @param array $token The auth token used to invoke the API |
||
85 | */ |
||
86 | do_action( 'jetpack_sync_remote_action', $action_name, $args, $user_id, $timestamp, $token ); |
||
87 | |||
88 | /** |
||
89 | * Fires when an action is received from a remote Jetpack site |
||
90 | * |
||
91 | * @since 4.1 |
||
92 | * |
||
93 | * @param array $args The arguments passed to the action |
||
94 | * @param int $user_id The external_user_id who did the action |
||
95 | * @param double $timestamp Timestamp (in seconds) when the action occurred |
||
96 | * @param array $token The auth token used to invoke the API |
||
97 | */ |
||
98 | do_action( 'jetpack_sync_' . $action_name, $args, $user_id, $timestamp, $token ); |
||
99 | |||
100 | $events_processed[] = $key; |
||
101 | |||
102 | if ( microtime( true ) - $start_time > self::MAX_TIME_PER_REQUEST_IN_SECONDS ) { |
||
103 | break; |
||
104 | } |
||
105 | } |
||
106 | |||
107 | if ( $token ) { |
||
108 | $this->remove_request_lock( $token->blog_id ); |
||
109 | } |
||
110 | |||
111 | return $events_processed; |
||
112 | } |
||
113 | } |
This check looks for improperly formatted assignments.
Every assignment must have exactly one space before and one space after the equals operator.
To illustrate:
will have no issues, while
will report issues in lines 1 and 2.