Completed
Push — fix/normalize-www-in-site-url-... ( e67e76 )
by
unknown
13:13 queued 02:59
created

WPCOM_JSON_API_Get_Comment_Endpoint   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 85.71 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 18
loc 21
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A callback() 18 18 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
class WPCOM_JSON_API_Get_Comment_Endpoint extends WPCOM_JSON_API_Comment_Endpoint {
4
	// /sites/%s/comments/%d -> $blog_id, $comment_id
5 View Code Duplication
	function callback( $path = '', $blog_id = 0, $comment_id = 0 ) {
6
		$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $blog_id. This often makes code more readable.
Loading history...
7
		if ( is_wp_error( $blog_id ) ) {
8
			return $blog_id;
9
		}
10
11
		$args = $this->query_args();
12
13
		$return = $this->get_comment( $comment_id, $args['context'] );
14
		if ( !$return || is_wp_error( $return ) ) {
15
			return $return;
16
		}
17
18
		/** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
19
		do_action( 'wpcom_json_api_objects', 'comments' );
20
21
		return $return;
22
	}
23
}
24