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_action( 'jetpack_xmlrpc_server_event', array( __CLASS__, 'jetpack_xmlrpc_server_event' ), 10, 4 ); |
||
25 | add_action( 'jetpack_remote_connect_end', array( __CLASS__, 'remote_connect_end' ) ); |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * Adds Jetpack specific methods to the methods added by the Connection package. |
||
30 | * |
||
31 | * @param array $methods Methods added by the Connection package. |
||
32 | */ |
||
33 | public static function xmlrpc_methods( $methods ) { |
||
34 | |||
35 | $methods['jetpack.featuresAvailable'] = array( __CLASS__, 'features_available' ); |
||
36 | $methods['jetpack.featuresEnabled'] = array( __CLASS__, 'features_enabled' ); |
||
37 | $methods['jetpack.disconnectBlog'] = array( __CLASS__, 'disconnect_blog' ); |
||
38 | $methods['jetpack.jsonAPI'] = array( __CLASS__, 'json_api' ); |
||
39 | |||
40 | return $methods; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Returns what features are available. Uses the slug of the module files. |
||
45 | * |
||
46 | * @return array |
||
47 | */ |
||
48 | View Code Duplication | public static function features_available() { |
|
57 | |||
58 | /** |
||
59 | * Returns what features are enabled. Uses the slug of the modules files. |
||
60 | * |
||
61 | * @return array |
||
62 | */ |
||
63 | View Code Duplication | public static function features_enabled() { |
|
72 | |||
73 | /** |
||
74 | * Filters the result of test_connection XMLRPC method |
||
75 | * |
||
76 | * @return string The current Jetpack version number |
||
77 | */ |
||
78 | public static function test_connection() { |
||
81 | |||
82 | /** |
||
83 | * Disconnect this blog from the connected wordpress.com account |
||
84 | * |
||
85 | * @return boolean |
||
86 | */ |
||
87 | public static function disconnect_blog() { |
||
102 | |||
103 | /** |
||
104 | * Serve a JSON API request. |
||
105 | * |
||
106 | * @param array $args request arguments. |
||
107 | */ |
||
108 | public static function json_api( $args = array() ) { |
||
199 | |||
200 | /** |
||
201 | * Runs Jetpack specific action in xmlrpc server events |
||
202 | * |
||
203 | * @param String $action the action name, i.e., 'remote_authorize'. |
||
204 | * @param String $stage the execution stage, can be 'begin', 'success', 'error', etc. |
||
205 | * @param array $parameters extra parameters from the event. |
||
206 | * @param WP_User $user the acting user. |
||
|
|||
207 | * @return void |
||
208 | */ |
||
209 | public static function jetpack_xmlrpc_server_event( $action, $stage, $parameters = array(), $user = null ) { //phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
214 | |||
215 | /** |
||
216 | * Hooks into the remote_connect XMLRPC endpoint and triggers Jetpack::handle_post_authorization_actions |
||
217 | * |
||
218 | * @since 9.8.0 |
||
219 | * @return void |
||
220 | */ |
||
221 | public static function remote_connect_end() { |
||
226 | } |
||
227 |
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.