Code Duplication    Length = 17-17 lines in 4 locations

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

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

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

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

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.