Code Duplication    Length = 15-17 lines in 3 locations

includes/api/legacy/v1/class-wc-api-server.php 1 location

@@ 159-173 (lines=15) @@
156
	 * @since 2.1
157
	 * @return WP_User|WP_Error WP_User object indicates successful login, WP_Error indicates unsuccessful login
158
	 */
159
	public function check_authentication() {
160
161
		// allow plugins to remove default authentication or add their own authentication
162
		$user = apply_filters( 'woocommerce_api_check_authentication', null, $this );
163
164
		// API requests run under the context of the authenticated user
165
		if ( is_a( $user, 'WP_User' ) )
166
			wp_set_current_user( $user->ID );
167
168
		// WP_Errors are handled in serve_request()
169
		elseif ( ! is_wp_error( $user ) )
170
			$user = new WP_Error( 'woocommerce_api_authentication_error', __( 'Invalid authentication method', 'woocommerce' ), array( 'code' => 500 ) );
171
172
		return $user;
173
	}
174
175
	/**
176
	 * Convert an error to an array

includes/api/legacy/v2/class-wc-api-server.php 1 location

@@ 152-168 (lines=17) @@
149
	 * @since 2.1
150
	 * @return WP_User|WP_Error WP_User object indicates successful login, WP_Error indicates unsuccessful login
151
	 */
152
	public function check_authentication() {
153
154
		// allow plugins to remove default authentication or add their own authentication
155
		$user = apply_filters( 'woocommerce_api_check_authentication', null, $this );
156
157
		// API requests run under the context of the authenticated user
158
		if ( is_a( $user, 'WP_User' ) ) {
159
			wp_set_current_user( $user->ID );
160
		}
161
162
		// WP_Errors are handled in serve_request()
163
		elseif ( ! is_wp_error( $user ) ) {
164
			$user = new WP_Error( 'woocommerce_api_authentication_error', __( 'Invalid authentication method', 'woocommerce' ), array( 'code' => 500 ) );
165
		}
166
167
		return $user;
168
	}
169
170
	/**
171
	 * Convert an error to an array

includes/api/legacy/v3/class-wc-api-server.php 1 location

@@ 152-168 (lines=17) @@
149
	 * @since 2.1
150
	 * @return WP_User|WP_Error WP_User object indicates successful login, WP_Error indicates unsuccessful login
151
	 */
152
	public function check_authentication() {
153
154
		// allow plugins to remove default authentication or add their own authentication
155
		$user = apply_filters( 'woocommerce_api_check_authentication', null, $this );
156
157
		// API requests run under the context of the authenticated user
158
		if ( is_a( $user, 'WP_User' ) ) {
159
			wp_set_current_user( $user->ID );
160
		}
161
162
		// WP_Errors are handled in serve_request()
163
		elseif ( ! is_wp_error( $user ) ) {
164
			$user = new WP_Error( 'woocommerce_api_authentication_error', __( 'Invalid authentication method', 'woocommerce' ), array( 'code' => 500 ) );
165
		}
166
167
		return $user;
168
	}
169
170
	/**
171
	 * Convert an error to an array