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 | * @return WP_REST_Response Connection information. |
||
| 154 | */ |
||
| 155 | public static function connection_status() { |
||
| 173 | |||
| 174 | |||
| 175 | /** |
||
| 176 | * Get plugins connected to the Jetpack. |
||
| 177 | * |
||
| 178 | * @since 8.6.0 |
||
| 179 | * |
||
| 180 | * @return WP_REST_Response|WP_Error Response or error object, depending on the request result. |
||
| 181 | */ |
||
| 182 | public function get_connection_plugins() { |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Verify that user can view Jetpack admin page and can activate plugins. |
||
| 201 | * |
||
| 202 | * @since 8.8.0 |
||
| 203 | * |
||
| 204 | * @return bool|WP_Error Whether user has the capability 'activate_plugins'. |
||
| 205 | */ |
||
| 206 | public static function activate_plugins_permission_check() { |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Verify that user is allowed to disconnect Jetpack. |
||
| 216 | * |
||
| 217 | * @since 8.8.0 |
||
| 218 | * |
||
| 219 | * @return bool|WP_Error Whether user has the capability 'jetpack_disconnect'. |
||
| 220 | */ |
||
| 221 | View Code Duplication | public static function jetpack_disconnect_permission_check() { |
|
| 228 | |||
| 229 | /** |
||
| 230 | * Returns generic error message when user is not allowed to perform an action. |
||
| 231 | * |
||
| 232 | * @return string The error message. |
||
| 233 | */ |
||
| 234 | public static function get_user_permissions_error_msg() { |
||
| 237 | |||
| 238 | /** |
||
| 239 | * The endpoint tried to partially or fully reconnect the website to WP.com. |
||
| 240 | * |
||
| 241 | * @since 8.8.0 |
||
| 242 | * |
||
| 243 | * @param WP_REST_Request $request The request sent to the WP REST API. |
||
| 244 | * |
||
| 245 | * @return \WP_REST_Response|WP_Error |
||
| 246 | */ |
||
| 247 | public function connection_reconnect( WP_REST_Request $request ) { |
||
| 270 | |||
| 271 | } |
||
| 272 |
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.