Code Duplication    Length = 17-17 lines in 4 locations

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

@@ 190-206 (lines=17) @@
187
	 * @param WP_REST_Request $request Request object.
188
	 * @return array Links for the given product review.
189
	 */
190
	protected function prepare_links( $review, $request ) {
191
		$product_id = (int) $request['product_id'];
192
		$base       = str_replace( '(?P<product_id>[\d]+)', $product_id, $this->rest_base );
193
		$links      = array(
194
			'self' => array(
195
				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $review->comment_ID ) ),
196
			),
197
			'collection' => array(
198
				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ),
199
			),
200
			'up' => array(
201
				'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product_id ) ),
202
			),
203
		);
204
205
		return $links;
206
	}
207
208
	/**
209
	 * Get the Product Review's schema, conforming to JSON Schema.

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

@@ 188-204 (lines=17) @@
185
	 * @param stdClass $log Delivery log object.
186
	 * @return array Links for the given webhook delivery.
187
	 */
188
	protected function prepare_links( $log ) {
189
		$webhook_id = (int) $log->request_headers['X-WC-Webhook-ID'];
190
		$base       = str_replace( '(?P<webhook_id>[\d]+)', $webhook_id, $this->rest_base );
191
		$links      = array(
192
			'self' => array(
193
				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $log->id ) ),
194
			),
195
			'collection' => array(
196
				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ),
197
			),
198
			'up' => array(
199
				'href' => rest_url( sprintf( '/%s/webhooks/%d', $this->namespace, $webhook_id ) ),
200
			),
201
		);
202
203
		return $links;
204
	}
205
206
	/**
207
	 * Get the Webhook's schema, conforming to JSON Schema.

includes/api/class-wc-rest-order-refunds-controller.php 1 location

@@ 226-242 (lines=17) @@
223
	 * @param WC_Order_Refund $refund Comment object.
224
	 * @return array Links for the given order refund.
225
	 */
226
	protected function prepare_links( $refund ) {
227
		$order_id = $refund->post->post_parent;
228
		$base     = str_replace( '(?P<order_id>[\d]+)', $order_id, $this->rest_base );
229
		$links    = array(
230
			'self' => array(
231
				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $refund->id ) ),
232
			),
233
			'collection' => array(
234
				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ),
235
			),
236
			'up' => array(
237
				'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $order_id ) ),
238
			),
239
		);
240
241
		return $links;
242
	}
243
244
	/**
245
	 * Query args.

includes/api/class-wc-rest-order-notes-controller.php 1 location

@@ 350-366 (lines=17) @@
347
	 * @param WP_Comment $note Delivery order_note object.
348
	 * @return array Links for the given order note.
349
	 */
350
	protected function prepare_links( $note ) {
351
		$order_id = (int) $note->comment_post_ID;
352
		$base     = str_replace( '(?P<order_id>[\d]+)', $order_id, $this->rest_base );
353
		$links    = array(
354
			'self' => array(
355
				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $note->comment_ID ) ),
356
			),
357
			'collection' => array(
358
				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ),
359
			),
360
			'up' => array(
361
				'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $order_id ) ),
362
			),
363
		);
364
365
		return $links;
366
	}
367
368
	/**
369
	 * Get the Order Notes schema, conforming to JSON Schema.