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  | 
            ||
| 5 | class WPCOM_REST_API_V2_Endpoint_Options extends WP_REST_Controller { | 
            ||
| 6 | /**  | 
            ||
| 7 | * Flag to help WordPress.com decide where it should look for  | 
            ||
| 8 | * Publicize data. Ignored for direct requests to Jetpack sites.  | 
            ||
| 9 | *  | 
            ||
| 10 | * @var bool $wpcom_is_wpcom_only_endpoint  | 
            ||
| 11 | */  | 
            ||
| 12 | public $wpcom_is_wpcom_only_endpoint = true;  | 
            ||
| 13 | |||
| 14 | 	public function __construct() { | 
            ||
| 20 | |||
| 21 | /**  | 
            ||
| 22 | * Called automatically on `rest_api_init()`.  | 
            ||
| 23 | */  | 
            ||
| 24 | View Code Duplication | 	public function register_routes() { | 
            |
| 38 | |||
| 39 | 	public function permission_check() { | 
            ||
| 42 | |||
| 43 | 	public function update_option( $request ) { | 
            ||
| 66 | |||
| 67 | |||
| 68 | /**  | 
            ||
| 69 | * @param WP_REST_Request $request  | 
            ||
| 70 | * @return WP_REST_Response suitable for 1-page collection  | 
            ||
| 71 | */  | 
            ||
| 72 | View Code Duplication | 	public function get_items( $request ) { | 
            |
| 85 | |||
| 86 | /**  | 
            ||
| 87 | * Filters out data based on ?_fields= request parameter  | 
            ||
| 88 | *  | 
            ||
| 89 | * @param array $connection  | 
            ||
| 90 | * @param WP_REST_Request $request  | 
            ||
| 91 | * @return array filtered $connection  | 
            ||
| 92 | */  | 
            ||
| 93 | View Code Duplication | 	public function prepare_item_for_response( $connection, $request ) { | 
            |
| 109 | |||
| 110 | /**  | 
            ||
| 111 | * Verify that user can access Publicize data  | 
            ||
| 112 | *  | 
            ||
| 113 | * @return true|WP_Error  | 
            ||
| 114 | */  | 
            ||
| 115 | View Code Duplication | 	public function get_items_permission_check() { | 
            |
| 128 | }  | 
            ||
| 129 | |||
| 131 |