Code Duplication    Length = 17-18 lines in 2 locations

includes/api/class-wc-rest-product-reviews-controller.php 1 location

@@ 102-118 (lines=17) @@
99
	 * @param WP_REST_Request $request
100
	 * @return array
101
	 */
102
	public function get_items( $request ) {
103
		$product = get_post( (int) $request['product_id'] );
104
105
		if ( empty( $product->post_type ) || 'product' !== $product->post_type ) {
106
			return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product id.', 'woocommerce' ), array( 'status' => 404 ) );
107
		}
108
109
		$reviews = get_approved_comments( $product->ID );
110
		$data    = array();
111
		foreach ( $reviews as $review_data ) {
112
			$review = $this->prepare_item_for_response( $review_data, $request );
113
			$review = $this->prepare_response_for_collection( $review );
114
			$data[] = $review;
115
		}
116
117
		return rest_ensure_response( $data );
118
	}
119
120
	/**
121
	 * Get a single product review.

includes/api/class-wc-rest-webhook-deliveries.php 1 location

@@ 102-119 (lines=18) @@
99
	 * @param WP_REST_Request $request
100
	 * @return array
101
	 */
102
	public function get_items( $request ) {
103
		$webhook = new WC_Webhook( (int) $request['webhook_id'] );
104
105
		if ( empty( $webhook->post_data->post_type ) || 'shop_webhook' !== $webhook->post_data->post_type ) {
106
			return new WP_Error( 'woocommerce_rest_webhook_invalid_id', __( 'Invalid webhook id.', 'woocommerce' ), array( 'status' => 404 ) );
107
		}
108
109
		$logs = $webhook->get_delivery_logs();
110
111
		$data = array();
112
		foreach ( $logs as $log ) {
113
			$delivery = $this->prepare_item_for_response( (object) $log, $request );
114
			$delivery = $this->prepare_response_for_collection( $delivery );
115
			$data[]   = $delivery;
116
		}
117
118
		return rest_ensure_response( $data );
119
	}
120
121
	/**
122
	 * Get a single webhook delivery.