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 |
||
| 20 | class REST_Connector { |
||
| 21 | /** |
||
| 22 | * The Connection Manager. |
||
| 23 | * |
||
| 24 | * @var Manager |
||
| 25 | */ |
||
| 26 | private $connection; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * This property stores the localized "Insufficient Permissions" error message. |
||
| 30 | * |
||
| 31 | * @var string Generic error message when user is not allowed to perform an action. |
||
| 32 | */ |
||
| 33 | private static $user_permissions_error_msg; |
||
| 34 | |||
| 35 | const JETPACK__DEBUGGER_PUBLIC_KEY = "\r\n" . '-----BEGIN PUBLIC KEY-----' . "\r\n" |
||
| 36 | . 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAm+uLLVoxGCY71LS6KFc6' . "\r\n" |
||
| 37 | . '1UnF6QGBAsi5XF8ty9kR3/voqfOkpW+gRerM2Kyjy6DPCOmzhZj7BFGtxSV2ZoMX' . "\r\n" |
||
| 38 | . '9ZwWxzXhl/Q/6k8jg8BoY1QL6L2K76icXJu80b+RDIqvOfJruaAeBg1Q9NyeYqLY' . "\r\n" |
||
| 39 | . 'lEVzN2vIwcFYl+MrP/g6Bc2co7Jcbli+tpNIxg4Z+Hnhbs7OJ3STQLmEryLpAxQO' . "\r\n" |
||
| 40 | . 'q8cbhQkMx+FyQhxzSwtXYI/ClCUmTnzcKk7SgGvEjoKGAmngILiVuEJ4bm7Q1yok' . "\r\n" |
||
| 41 | . 'xl9+wcfW6JAituNhml9dlHCWnn9D3+j8pxStHihKy2gVMwiFRjLEeD8K/7JVGkb/' . "\r\n" |
||
| 42 | . 'EwIDAQAB' . "\r\n" |
||
| 43 | . '-----END PUBLIC KEY-----' . "\r\n"; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Constructor. |
||
| 47 | * |
||
| 48 | * @param Manager $connection The Connection Manager. |
||
| 49 | */ |
||
| 50 | public function __construct( Manager $connection ) { |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Handles verification that a site is registered. |
||
| 119 | * |
||
| 120 | * @since 5.4.0 |
||
| 121 | * |
||
| 122 | * @param WP_REST_Request $request The request sent to the WP REST API. |
||
| 123 | * |
||
| 124 | * @return string|WP_Error |
||
| 125 | */ |
||
| 126 | public function verify_registration( WP_REST_Request $request ) { |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Handles verification that a site is registered |
||
| 134 | * |
||
| 135 | * @since 5.4.0 |
||
| 136 | * |
||
| 137 | * @param WP_REST_Request $request The request sent to the WP REST API. |
||
| 138 | * |
||
| 139 | * @return array|wp-error |
||
|
|
|||
| 140 | */ |
||
| 141 | public static function remote_authorize( $request ) { |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Get connection status for this Jetpack site. |
||
| 154 | * |
||
| 155 | * @since 4.3.0 |
||
| 156 | * |
||
| 157 | * @param bool $rest_response Should we return a rest response or a simple array. Default to rest response. |
||
| 158 | * |
||
| 159 | * @return WP_REST_Response|array Connection information. |
||
| 160 | */ |
||
| 161 | public static function connection_status( $rest_response = true ) { |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Get plugins connected to the Jetpack. |
||
| 192 | * |
||
| 193 | * @since 8.6.0 |
||
| 194 | * |
||
| 195 | * @return WP_REST_Response|WP_Error Response or error object, depending on the request result. |
||
| 196 | */ |
||
| 197 | public function get_connection_plugins() { |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Verify that user can view Jetpack admin page and can activate plugins. |
||
| 216 | * |
||
| 217 | * @since 8.8.0 |
||
| 218 | * |
||
| 219 | * @return bool|WP_Error Whether user has the capability 'activate_plugins'. |
||
| 220 | */ |
||
| 221 | public static function activate_plugins_permission_check() { |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Permission check for the connection_plugins endpoint |
||
| 231 | * |
||
| 232 | * @return bool|WP_Error |
||
| 233 | */ |
||
| 234 | public static function connection_plugins_permission_check() { |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Verifies if the request was signed with the Jetpack Debugger key |
||
| 249 | * |
||
| 250 | * @return bool |
||
| 251 | */ |
||
| 252 | View Code Duplication | public static function is_request_signed_by_jetpack_debugger() { |
|
| 287 | |||
| 288 | /** |
||
| 289 | * Verify that user is allowed to disconnect Jetpack. |
||
| 290 | * |
||
| 291 | * @since 8.8.0 |
||
| 292 | * |
||
| 293 | * @return bool|WP_Error Whether user has the capability 'jetpack_disconnect'. |
||
| 294 | */ |
||
| 295 | public static function jetpack_reconnect_permission_check() { |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Returns generic error message when user is not allowed to perform an action. |
||
| 305 | * |
||
| 306 | * @return string The error message. |
||
| 307 | */ |
||
| 308 | public static function get_user_permissions_error_msg() { |
||
| 311 | |||
| 312 | /** |
||
| 313 | * The endpoint tried to partially or fully reconnect the website to WP.com. |
||
| 314 | * |
||
| 315 | * @since 8.8.0 |
||
| 316 | * |
||
| 317 | * @return \WP_REST_Response|WP_Error |
||
| 318 | */ |
||
| 319 | public function connection_reconnect() { |
||
| 355 | |||
| 356 | } |
||
| 357 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.