Code Duplication    Length = 18-20 lines in 2 locations

json-endpoints/class.wpcom-json-api-sharing-buttons-endpoint.php 1 location

@@ 302-321 (lines=20) @@
299
class WPCOM_JSON_API_Get_Sharing_Button_Endpoint extends WPCOM_JSON_API_Sharing_Button_Endpoint {
300
301
	// GET /sites/%s/sharing-buttons/%s -> $blog_id, $button_id
302
	public function callback( $path = '', $blog_id = 0, $button_id = 0 ) {
303
		// Validate request
304
		$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
305
		if ( is_wp_error( $blog_id ) ) {
306
			return $blog_id;
307
		}
308
309
		$continue = $this->setup();
310
		if ( is_wp_error( $continue ) ) {
311
			return $continue;
312
		}
313
314
		// Search existing services for button
315
		$all_buttons = $this->sharing_service->get_all_services_blog();
316
		if ( ! array_key_exists( $button_id, $all_buttons ) ) {
317
			return new WP_Error( 'not_found', 'The specified sharing button was not found', 404 );
318
		} else {
319
			return $this->format_sharing_button( $all_buttons[ $button_id ] );
320
		}
321
	}
322
323
}
324

json-endpoints/class.wpcom-json-api-get-comment-endpoint.php 1 location

@@ 22-39 (lines=18) @@
19
20
class WPCOM_JSON_API_Get_Comment_Endpoint extends WPCOM_JSON_API_Comment_Endpoint {
21
	// /sites/%s/comments/%d -> $blog_id, $comment_id
22
	function callback( $path = '', $blog_id = 0, $comment_id = 0 ) {
23
		$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
24
		if ( is_wp_error( $blog_id ) ) {
25
			return $blog_id;
26
		}
27
28
		$args = $this->query_args();
29
30
		$return = $this->get_comment( $comment_id, $args['context'] );
31
		if ( !$return || is_wp_error( $return ) ) {
32
			return $return;
33
		}
34
35
		/** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
36
		do_action( 'wpcom_json_api_objects', 'comments' );
37
38
		return $return;
39
	}
40
}
41