Conditions | 1 |
Paths | 1 |
Total Lines | 267 |
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 |
||
31 | public static function initialize_rest_api() { |
||
32 | |||
33 | // Request a Full Sync. |
||
34 | register_rest_route( |
||
35 | 'jetpack/v4', |
||
36 | '/sync/full-sync', |
||
37 | array( |
||
38 | 'methods' => WP_REST_Server::EDITABLE, |
||
39 | 'callback' => __CLASS__ . '::full_sync_start', |
||
40 | 'permission_callback' => __CLASS__ . '::verify_default_permissions', |
||
41 | 'args' => array( |
||
42 | 'modules' => array( |
||
43 | 'description' => __( 'Data Modules that should be included in Full Sync', 'jetpack' ), |
||
44 | 'type' => 'array', |
||
45 | 'required' => false, |
||
46 | ), |
||
47 | 'users' => array( |
||
48 | 'description' => __( 'User IDs to include in Full Sync or "initial"', 'jetpack' ), |
||
49 | 'required' => false, |
||
50 | ), |
||
51 | 'posts' => array( |
||
52 | 'description' => __( 'Post IDs to include in Full Sync', 'jetpack' ), |
||
53 | 'type' => 'array', |
||
54 | 'required' => false, |
||
55 | ), |
||
56 | 'comments' => array( |
||
57 | 'description' => __( 'Comment IDs to include in Full Sync', 'jetpack' ), |
||
58 | 'type' => 'array', |
||
59 | 'required' => false, |
||
60 | ), |
||
61 | ), |
||
62 | ) |
||
63 | ); |
||
64 | |||
65 | // Obtain Sync status. |
||
66 | register_rest_route( |
||
67 | 'jetpack/v4', |
||
68 | '/sync/status', |
||
69 | array( |
||
70 | 'methods' => WP_REST_Server::READABLE, |
||
71 | 'callback' => __CLASS__ . '::sync_status', |
||
72 | 'permission_callback' => __CLASS__ . '::verify_default_permissions', |
||
73 | 'args' => array( |
||
74 | 'fields' => array( |
||
75 | 'description' => __( 'Comma seperated list of additional fields that should be included in status.', 'jetpack' ), |
||
76 | 'type' => 'string', |
||
77 | 'required' => false, |
||
78 | ), |
||
79 | ), |
||
80 | ) |
||
81 | ); |
||
82 | |||
83 | // Update Sync health status. |
||
84 | register_rest_route( |
||
85 | 'jetpack/v4', |
||
86 | '/sync/health', |
||
87 | array( |
||
88 | 'methods' => WP_REST_Server::EDITABLE, |
||
89 | 'callback' => __CLASS__ . '::sync_health', |
||
90 | 'permission_callback' => __CLASS__ . '::verify_default_permissions', |
||
91 | 'args' => array( |
||
92 | 'status' => array( |
||
93 | 'description' => __( 'New Sync health status', 'jetpack' ), |
||
94 | 'type' => 'string', |
||
95 | 'required' => true, |
||
96 | ), |
||
97 | ), |
||
98 | ) |
||
99 | ); |
||
100 | |||
101 | // Obtain Sync settings. |
||
102 | register_rest_route( |
||
103 | 'jetpack/v4', |
||
104 | '/sync/settings', |
||
105 | array( |
||
106 | array( |
||
107 | 'methods' => WP_REST_Server::READABLE, |
||
108 | 'callback' => __CLASS__ . '::get_sync_settings', |
||
109 | 'permission_callback' => __CLASS__ . '::verify_default_permissions', |
||
110 | ), |
||
111 | array( |
||
112 | 'methods' => WP_REST_Server::EDITABLE, |
||
113 | 'callback' => __CLASS__ . '::update_sync_settings', |
||
114 | 'permission_callback' => __CLASS__ . '::verify_default_permissions', |
||
115 | ), |
||
116 | ) |
||
117 | ); |
||
118 | |||
119 | // Retrieve Sync Object(s). |
||
120 | register_rest_route( |
||
121 | 'jetpack/v4', |
||
122 | '/sync/object', |
||
123 | array( |
||
124 | 'methods' => WP_REST_Server::READABLE, |
||
125 | 'callback' => __CLASS__ . '::get_sync_objects', |
||
126 | 'permission_callback' => __CLASS__ . '::verify_default_permissions', |
||
127 | 'args' => array( |
||
128 | 'module_name' => array( |
||
129 | 'description' => __( 'Name of Sync module', 'jetpack' ), |
||
130 | 'type' => 'string', |
||
131 | 'required' => false, |
||
132 | ), |
||
133 | 'object_type' => array( |
||
134 | 'description' => __( 'Object Type', 'jetpack' ), |
||
135 | 'type' => 'string', |
||
136 | 'required' => false, |
||
137 | ), |
||
138 | 'object_ids' => array( |
||
139 | 'description' => __( 'Objects Identifiers', 'jetpack' ), |
||
140 | 'type' => 'array', |
||
141 | 'required' => false, |
||
142 | ), |
||
143 | ), |
||
144 | ) |
||
145 | ); |
||
146 | |||
147 | // Retrieve Sync Object(s). |
||
148 | register_rest_route( |
||
149 | 'jetpack/v4', |
||
150 | '/sync/now', |
||
151 | array( |
||
152 | 'methods' => WP_REST_Server::EDITABLE, |
||
153 | 'callback' => __CLASS__ . '::do_sync', |
||
154 | 'permission_callback' => __CLASS__ . '::verify_default_permissions', |
||
155 | 'args' => array( |
||
156 | 'queue' => array( |
||
157 | 'description' => __( 'Name of Sync queue.', 'jetpack' ), |
||
158 | 'type' => 'string', |
||
159 | 'required' => true, |
||
160 | ), |
||
161 | ), |
||
162 | ) |
||
163 | ); |
||
164 | |||
165 | // Checkout Sync Objects. |
||
166 | register_rest_route( |
||
167 | 'jetpack/v4', |
||
168 | '/sync/checkout', |
||
169 | array( |
||
170 | 'methods' => WP_REST_Server::EDITABLE, |
||
171 | 'callback' => __CLASS__ . '::checkout', |
||
172 | 'permission_callback' => __CLASS__ . '::verify_default_permissions', |
||
173 | ) |
||
174 | ); |
||
175 | |||
176 | // Checkin Sync Objects. |
||
177 | register_rest_route( |
||
178 | 'jetpack/v4', |
||
179 | '/sync/close', |
||
180 | array( |
||
181 | 'methods' => WP_REST_Server::EDITABLE, |
||
182 | 'callback' => __CLASS__ . '::close', |
||
183 | 'permission_callback' => __CLASS__ . '::verify_default_permissions', |
||
184 | ) |
||
185 | ); |
||
186 | |||
187 | // Unlock Sync Queue. |
||
188 | register_rest_route( |
||
189 | 'jetpack/v4', |
||
190 | '/sync/unlock', |
||
191 | array( |
||
192 | 'methods' => WP_REST_Server::EDITABLE, |
||
193 | 'callback' => __CLASS__ . '::unlock_queue', |
||
194 | 'permission_callback' => __CLASS__ . '::verify_default_permissions', |
||
195 | 'args' => array( |
||
196 | 'queue' => array( |
||
197 | 'description' => __( 'Name of Sync queue.', 'jetpack' ), |
||
198 | 'type' => 'string', |
||
199 | 'required' => true, |
||
200 | ), |
||
201 | ), |
||
202 | ) |
||
203 | ); |
||
204 | |||
205 | // Retrieve range of Object Ids. |
||
206 | register_rest_route( |
||
207 | 'jetpack/v4', |
||
208 | '/sync/object-id-range', |
||
209 | array( |
||
210 | 'methods' => WP_REST_Server::READABLE, |
||
211 | 'callback' => __CLASS__ . '::get_object_id_range', |
||
212 | 'permission_callback' => __CLASS__ . '::verify_default_permissions', |
||
213 | 'args' => array( |
||
214 | 'sync_module' => array( |
||
215 | 'description' => __( 'Name of Sync module.', 'jetpack' ), |
||
216 | 'type' => 'string', |
||
217 | 'required' => true, |
||
218 | ), |
||
219 | 'batch_size' => array( |
||
220 | 'description' => __( 'Size of batches', 'jetpack' ), |
||
221 | 'type' => 'int', |
||
222 | 'required' => true, |
||
223 | ), |
||
224 | ), |
||
225 | ) |
||
226 | ); |
||
227 | |||
228 | // Obtain table checksums. |
||
229 | register_rest_route( |
||
230 | 'jetpack/v4', |
||
231 | '/sync/data-check', |
||
232 | array( |
||
233 | 'methods' => WP_REST_Server::READABLE, |
||
234 | 'callback' => __CLASS__ . '::data_check', |
||
235 | 'permission_callback' => __CLASS__ . '::verify_default_permissions', |
||
236 | ) |
||
237 | ); |
||
238 | |||
239 | // Obtain histogram. |
||
240 | register_rest_route( |
||
241 | 'jetpack/v4', |
||
242 | '/sync/data-histogram', |
||
243 | array( |
||
244 | 'methods' => WP_REST_Server::EDITABLE, |
||
245 | 'callback' => __CLASS__ . '::data_histogram', |
||
246 | 'permission_callback' => __CLASS__ . '::verify_default_permissions', |
||
247 | 'args' => array( |
||
248 | 'columns' => array( |
||
249 | 'description' => __( 'Column mappings', 'jetpack' ), |
||
250 | 'type' => 'array', |
||
251 | 'required' => false, |
||
252 | ), |
||
253 | 'object_type' => array( |
||
254 | 'description' => __( 'Object Type', 'jetpack' ), |
||
255 | 'type' => 'string', |
||
256 | 'required' => false, |
||
257 | ), |
||
258 | 'buckets' => array( |
||
259 | 'description' => __( 'Number of histogram buckets.', 'jetpack' ), |
||
260 | 'type' => 'int', |
||
261 | 'required' => false, |
||
262 | ), |
||
263 | 'start_id' => array( |
||
264 | 'description' => __( 'Start ID for the histogram', 'jetpack' ), |
||
265 | 'type' => 'int', |
||
266 | 'required' => false, |
||
267 | ), |
||
268 | 'end_id' => array( |
||
269 | 'description' => __( 'End ID for the histogram', 'jetpack' ), |
||
270 | 'type' => 'int', |
||
271 | 'required' => false, |
||
272 | ), |
||
273 | 'strip_non_ascii' => array( |
||
274 | 'description' => __( 'Strip non-ascii characters?', 'jetpack' ), |
||
275 | 'type' => 'boolean', |
||
276 | 'required' => false, |
||
277 | ), |
||
278 | 'shared_salt' => array( |
||
279 | 'description' => __( 'Shared Salt to use when generating checksum', 'jetpack' ), |
||
280 | 'type' => 'string', |
||
281 | 'required' => false, |
||
282 | ), |
||
283 | 'only_range_edges' => array( |
||
284 | 'description' => __( 'Should only range endges be returned', 'jetpack' ), |
||
285 | 'type' => 'boolean', |
||
286 | 'required' => false, |
||
287 | ), |
||
288 | 'detailed_drilldown' => array( |
||
289 | 'description' => __( 'Do we want the checksum or object ids.', 'jetpack' ), |
||
290 | 'type' => 'boolean', |
||
291 | 'required' => false, |
||
292 | ), |
||
293 | ), |
||
294 | ) |
||
295 | ); |
||
296 | |||
297 | } |
||
298 | |||
781 |
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.