Completed
Push — add/core-api-ping ( 2e6549 )
by
unknown
07:30
created

WPCOM_REST_API_V2_Endpoint_Ping   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 40 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 8
loc 20
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A register_routes() 8 8 1
A get_data() 0 4 1

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_REST_API_V2_Endpoint_Ping {
4
5
	public function __construct() {
6
		add_action( 'rest_api_init', array( $this, 'register_routes' ) );
7
	}
8
9 View Code Duplication
	public function register_routes() {
10
		register_rest_route( 'wpcom/v2', '/ping', array(
11
			array(
12
				'methods'  => WP_REST_Server::READABLE,
13
				'callback' => array( $this, 'get_data' ),
14
			),
15
		) );
16
	}
17
18
	public function get_data( $request ) {
19
		sleep(3);
20
		return array( 'end' => time() );
21
	}
22
}
23
24
wpcom_rest_api_v2_load_plugin( 'WPCOM_REST_API_V2_Endpoint_Ping' );
25