Conditions | 7 |
Paths | 8 |
Total Lines | 63 |
Lines | 0 |
Ratio | 0 % |
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 |
||
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, $silent ) = $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 bool $silent Whether the item was created via import |
||
86 | * @param double $timestamp Timestamp (in seconds) when the action occurred |
||
87 | * @param double $sent_timestamp Timestamp (in seconds) when the action was transmitted |
||
88 | * @param string $queue_id ID of the queue from which the event was sent (sync or full_sync) |
||
89 | * @param array $token The auth token used to invoke the API |
||
90 | */ |
||
91 | do_action( 'jetpack_sync_remote_action', $action_name, $args, $user_id, $silent, $timestamp, $sent_timestamp, $queue_id, $token ); |
||
92 | |||
93 | $events_processed[] = $key; |
||
94 | |||
95 | if ( microtime( true ) - $start_time > self::MAX_TIME_PER_REQUEST_IN_SECONDS ) { |
||
96 | break; |
||
97 | } |
||
98 | } |
||
99 | |||
100 | if ( $token ) { |
||
101 | $this->remove_request_lock( $token->blog_id ); |
||
102 | } |
||
103 | |||
104 | return $events_processed; |
||
105 | } |
||
106 | } |
||
107 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.