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 |
||
8 | class WPCOM_REST_API_V2_Endpoint_Subscribers extends WP_REST_Controller { |
||
9 | View Code Duplication | function __construct() { |
|
10 | $this->namespace = 'wpcom/v2'; |
||
11 | $this->rest_base = 'subscribers'; |
||
12 | // This endpoint *does not* need to connect directly to Jetpack sites. |
||
13 | $this->wpcom_is_wpcom_only_endpoint = true; |
||
14 | add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
||
15 | } |
||
16 | |||
17 | public function register_routes() { |
||
27 | |||
28 | public function readable_permission_check() { |
||
35 | |||
36 | /** |
||
37 | * Retrieves subscriber count |
||
38 | * |
||
39 | * @param WP_REST_Request $request incoming API request info |
||
40 | * @return array data object containing subscriber count |
||
41 | */ |
||
42 | public function get_subscriber_count( $request ) { |
||
51 | } |
||
52 | |||
56 |