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 | /** |
||
| 36 | * Constructor. |
||
| 37 | * |
||
| 38 | * @param Manager $connection The Connection Manager. |
||
| 39 | */ |
||
| 40 | public function __construct( Manager $connection ) { |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Handles verification that a site is registered. |
||
| 115 | * |
||
| 116 | * @since 5.4.0 |
||
| 117 | * |
||
| 118 | * @param WP_REST_Request $request The request sent to the WP REST API. |
||
| 119 | * |
||
| 120 | * @return string|WP_Error |
||
| 121 | */ |
||
| 122 | public function verify_registration( WP_REST_Request $request ) { |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Handles verification that a site is registered |
||
| 130 | * |
||
| 131 | * @since 5.4.0 |
||
| 132 | * |
||
| 133 | * @param WP_REST_Request $request The request sent to the WP REST API. |
||
| 134 | * |
||
| 135 | * @return array|wp-error |
||
|
|
|||
| 136 | */ |
||
| 137 | public static function remote_authorize( $request ) { |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Get connection status for this Jetpack site. |
||
| 150 | * |
||
| 151 | * @since 4.3.0 |
||
| 152 | * |
||
| 153 | * @param bool $rest_response Should we return a rest response or a simple array. Default to rest response. |
||
| 154 | * |
||
| 155 | * @return WP_REST_Response|array Connection information. |
||
| 156 | */ |
||
| 157 | public static function connection_status( $rest_response = true ) { |
||
| 184 | |||
| 185 | |||
| 186 | /** |
||
| 187 | * Get plugins connected to the Jetpack. |
||
| 188 | * |
||
| 189 | * @since 8.6.0 |
||
| 190 | * |
||
| 191 | * @return WP_REST_Response|WP_Error Response or error object, depending on the request result. |
||
| 192 | */ |
||
| 193 | public function get_connection_plugins() { |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Verify that user can view Jetpack admin page and can activate plugins. |
||
| 212 | * |
||
| 213 | * @since 8.8.0 |
||
| 214 | * |
||
| 215 | * @return bool|WP_Error Whether user has the capability 'activate_plugins'. |
||
| 216 | */ |
||
| 217 | public static function activate_plugins_permission_check() { |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Verify that user is allowed to disconnect Jetpack. |
||
| 227 | * |
||
| 228 | * @since 8.8.0 |
||
| 229 | * |
||
| 230 | * @return bool|WP_Error Whether user has the capability 'jetpack_disconnect'. |
||
| 231 | */ |
||
| 232 | View Code Duplication | public static function jetpack_disconnect_permission_check() { |
|
| 239 | |||
| 240 | /** |
||
| 241 | * Returns generic error message when user is not allowed to perform an action. |
||
| 242 | * |
||
| 243 | * @return string The error message. |
||
| 244 | */ |
||
| 245 | public static function get_user_permissions_error_msg() { |
||
| 248 | |||
| 249 | /** |
||
| 250 | * The endpoint tried to partially or fully reconnect the website to WP.com. |
||
| 251 | * |
||
| 252 | * @since 8.8.0 |
||
| 253 | * |
||
| 254 | * @param WP_REST_Request $request The request sent to the WP REST API. |
||
| 255 | * |
||
| 256 | * @return \WP_REST_Response|WP_Error |
||
| 257 | */ |
||
| 258 | public function connection_reconnect( WP_REST_Request $request ) { |
||
| 281 | |||
| 282 | } |
||
| 283 |
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.