Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
16 | class Jetpack_XMLRPC_Methods { |
||
17 | |||
18 | /** |
||
19 | * Initialize the main hooks. |
||
20 | */ |
||
21 | public static function init() { |
||
22 | add_filter( 'jetpack_xmlrpc_unauthenticated_methods', array( __CLASS__, 'xmlrpc_methods' ) ); |
||
23 | add_filter( 'jetpack_xmlrpc_test_connection_response', array( __CLASS__, 'test_connection' ) ); |
||
24 | add_filter( 'jetpack_remote_xmlrpc_provision_response', array( __CLASS__, 'remote_provision_response' ), 10, 2 ); |
||
25 | add_action( 'jetpack_xmlrpc_server_event', array( __CLASS__, 'jetpack_xmlrpc_server_event' ), 10, 4 ); |
||
26 | add_action( 'jetpack_remote_connect_end', array( __CLASS__, 'remote_connect_end' ) ); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * Adds Jetpack specific methods to the methods added by the Connection package. |
||
31 | * |
||
32 | * @param array $methods Methods added by the Connection package. |
||
33 | */ |
||
34 | public static function xmlrpc_methods( $methods ) { |
||
35 | |||
36 | $methods['jetpack.featuresAvailable'] = array( __CLASS__, 'features_available' ); |
||
37 | $methods['jetpack.featuresEnabled'] = array( __CLASS__, 'features_enabled' ); |
||
38 | $methods['jetpack.disconnectBlog'] = array( __CLASS__, 'disconnect_blog' ); |
||
39 | $methods['jetpack.jsonAPI'] = array( __CLASS__, 'json_api' ); |
||
40 | |||
41 | return $methods; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Returns what features are available. Uses the slug of the module files. |
||
46 | * |
||
47 | * @return array |
||
48 | */ |
||
49 | View Code Duplication | public static function features_available() { |
|
58 | |||
59 | /** |
||
60 | * Returns what features are enabled. Uses the slug of the modules files. |
||
61 | * |
||
62 | * @return array |
||
63 | */ |
||
64 | View Code Duplication | public static function features_enabled() { |
|
73 | |||
74 | /** |
||
75 | * Filters the result of test_connection XMLRPC method |
||
76 | * |
||
77 | * @return string The current Jetpack version number |
||
78 | */ |
||
79 | public static function test_connection() { |
||
82 | |||
83 | /** |
||
84 | * Disconnect this blog from the connected wordpress.com account |
||
85 | * |
||
86 | * @return boolean |
||
87 | */ |
||
88 | public static function disconnect_blog() { |
||
103 | |||
104 | /** |
||
105 | * Serve a JSON API request. |
||
106 | * |
||
107 | * @param array $args request arguments. |
||
108 | */ |
||
109 | public static function json_api( $args = array() ) { |
||
200 | |||
201 | /** |
||
202 | * Filters the response of the remote_provision XMLRPC method |
||
203 | * |
||
204 | * @param array $response The response. |
||
205 | * @param array $request An array containing at minimum a nonce key and a local_username key. |
||
206 | * |
||
207 | * @since 9.8.0 |
||
208 | * @return array |
||
209 | */ |
||
210 | public static function remote_provision_response( $response, $request ) { |
||
217 | |||
218 | /** |
||
219 | * Runs Jetpack specific action in xmlrpc server events |
||
220 | * |
||
221 | * @param String $action the action name, i.e., 'remote_authorize'. |
||
222 | * @param String $stage the execution stage, can be 'begin', 'success', 'error', etc. |
||
223 | * @param array $parameters extra parameters from the event. |
||
224 | * @param WP_User $user the acting user. |
||
|
|||
225 | * @return void |
||
226 | */ |
||
227 | public static function jetpack_xmlrpc_server_event( $action, $stage, $parameters = array(), $user = null ) { //phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
232 | |||
233 | /** |
||
234 | * Hooks into the remote_connect XMLRPC endpoint and triggers Jetpack::handle_post_authorization_actions |
||
235 | * |
||
236 | * @since 9.8.0 |
||
237 | * @return void |
||
238 | */ |
||
239 | public static function remote_connect_end() { |
||
244 | } |
||
245 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.