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 |
||
10 | class WPCOM_REST_API_V2_Endpoint_Mailchimp extends WP_REST_Controller { |
||
11 | View Code Duplication | public function __construct() { |
|
12 | $this->namespace = 'wpcom/v2'; |
||
13 | $this->rest_base = 'mailchimp'; |
||
14 | $this->wpcom_is_wpcom_only_endpoint = true; |
||
15 | |||
16 | add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
||
17 | } |
||
18 | |||
19 | /** |
||
20 | * Called automatically on `rest_api_init()`. |
||
21 | */ |
||
22 | View Code Duplication | public function register_routes() { |
|
23 | register_rest_route( |
||
24 | $this->namespace, |
||
25 | $this->rest_base, |
||
26 | array( |
||
27 | array( |
||
28 | 'methods' => WP_REST_Server::READABLE, |
||
29 | 'callback' => array( $this, 'get_mailchimp_status' ), |
||
30 | ), |
||
31 | ) |
||
32 | ); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Check if MailChimp is set up properly. |
||
37 | * |
||
38 | * @return bool |
||
39 | */ |
||
40 | private function is_connected() { |
||
51 | |||
52 | /** |
||
53 | * Get the status of current blog's Mailchimp connection |
||
54 | * |
||
55 | * @return mixed |
||
56 | * code:string (connected|unconnected), |
||
57 | * connect_url:string |
||
58 | * site_id:int |
||
59 | */ |
||
60 | public function get_mailchimp_status() { |
||
77 | } |
||
78 | |||
80 |