Code Duplication    Length = 45-46 lines in 3 locations

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

@@ 205-249 (lines=45) @@
202
	 * @since 2.1
203
	 * @uses WC_API_Server::dispatch()
204
	 */
205
	public function serve_request() {
206
207
		do_action( 'woocommerce_api_server_before_serve', $this );
208
209
		$this->header( 'Content-Type', $this->handler->get_content_type(), true );
210
211
		// the API is enabled by default
212
		if ( ! apply_filters( 'woocommerce_api_enabled', true, $this ) || ( 'no' === get_option( 'woocommerce_api_enabled' ) ) ) {
213
214
			$this->send_status( 404 );
215
216
			echo $this->handler->generate_response( array( 'errors' => array( 'code' => 'woocommerce_api_disabled', 'message' => 'The WooCommerce API is disabled on this site' ) ) );
217
218
			return;
219
		}
220
221
		$result = $this->check_authentication();
222
223
		// if authorization check was successful, dispatch the request
224
		if ( ! is_wp_error( $result ) ) {
225
			$result = $this->dispatch();
226
		}
227
228
		// handle any dispatch errors
229
		if ( is_wp_error( $result ) ) {
230
			$data = $result->get_error_data();
231
			if ( is_array( $data ) && isset( $data['status'] ) ) {
232
				$this->send_status( $data['status'] );
233
			}
234
235
			$result = $this->error_to_array( $result );
236
		}
237
238
		// This is a filter rather than an action, since this is designed to be
239
		// re-entrant if needed
240
		$served = apply_filters( 'woocommerce_api_serve_request', false, $result, $this );
241
242
		if ( ! $served ) {
243
244
			if ( 'HEAD' === $this->method )
245
				return;
246
247
			echo $this->handler->generate_response( $result );
248
		}
249
	}
250
251
	/**
252
	 * Retrieve the route map

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

@@ 201-246 (lines=46) @@
198
	 * @since 2.1
199
	 * @uses WC_API_Server::dispatch()
200
	 */
201
	public function serve_request() {
202
203
		do_action( 'woocommerce_api_server_before_serve', $this );
204
205
		$this->header( 'Content-Type', $this->handler->get_content_type(), true );
206
207
		// the API is enabled by default
208
		if ( ! apply_filters( 'woocommerce_api_enabled', true, $this ) || ( 'no' === get_option( 'woocommerce_api_enabled' ) ) ) {
209
210
			$this->send_status( 404 );
211
212
			echo $this->handler->generate_response( array( 'errors' => array( 'code' => 'woocommerce_api_disabled', 'message' => 'The WooCommerce API is disabled on this site' ) ) );
213
214
			return;
215
		}
216
217
		$result = $this->check_authentication();
218
219
		// if authorization check was successful, dispatch the request
220
		if ( ! is_wp_error( $result ) ) {
221
			$result = $this->dispatch();
222
		}
223
224
		// handle any dispatch errors
225
		if ( is_wp_error( $result ) ) {
226
			$data = $result->get_error_data();
227
			if ( is_array( $data ) && isset( $data['status'] ) ) {
228
				$this->send_status( $data['status'] );
229
			}
230
231
			$result = $this->error_to_array( $result );
232
		}
233
234
		// This is a filter rather than an action, since this is designed to be
235
		// re-entrant if needed
236
		$served = apply_filters( 'woocommerce_api_serve_request', false, $result, $this );
237
238
		if ( ! $served ) {
239
240
			if ( 'HEAD' === $this->method ) {
241
				return;
242
			}
243
244
			echo $this->handler->generate_response( $result );
245
		}
246
	}
247
248
	/**
249
	 * Retrieve the route map

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

@@ 201-246 (lines=46) @@
198
	 * @since 2.1
199
	 * @uses WC_API_Server::dispatch()
200
	 */
201
	public function serve_request() {
202
203
		do_action( 'woocommerce_api_server_before_serve', $this );
204
205
		$this->header( 'Content-Type', $this->handler->get_content_type(), true );
206
207
		// the API is enabled by default
208
		if ( ! apply_filters( 'woocommerce_api_enabled', true, $this ) || ( 'no' === get_option( 'woocommerce_api_enabled' ) ) ) {
209
210
			$this->send_status( 404 );
211
212
			echo $this->handler->generate_response( array( 'errors' => array( 'code' => 'woocommerce_api_disabled', 'message' => 'The WooCommerce API is disabled on this site' ) ) );
213
214
			return;
215
		}
216
217
		$result = $this->check_authentication();
218
219
		// if authorization check was successful, dispatch the request
220
		if ( ! is_wp_error( $result ) ) {
221
			$result = $this->dispatch();
222
		}
223
224
		// handle any dispatch errors
225
		if ( is_wp_error( $result ) ) {
226
			$data = $result->get_error_data();
227
			if ( is_array( $data ) && isset( $data['status'] ) ) {
228
				$this->send_status( $data['status'] );
229
			}
230
231
			$result = $this->error_to_array( $result );
232
		}
233
234
		// This is a filter rather than an action, since this is designed to be
235
		// re-entrant if needed
236
		$served = apply_filters( 'woocommerce_api_serve_request', false, $result, $this );
237
238
		if ( ! $served ) {
239
240
			if ( 'HEAD' === $this->method ) {
241
				return;
242
			}
243
244
			echo $this->handler->generate_response( $result );
245
		}
246
	}
247
248
	/**
249
	 * Retrieve the route map