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 |
||
17 | class CMB2_REST_Controller_Boxes extends CMB2_REST_Controller { |
||
|
|||
18 | |||
19 | /** |
||
20 | * Register the routes for the objects of the controller. |
||
21 | * |
||
22 | * @since 2.2.0 |
||
23 | */ |
||
24 | View Code Duplication | public function register_routes() { |
|
45 | |||
46 | /** |
||
47 | * Get all public fields |
||
48 | * |
||
49 | * @since 2.2.0 |
||
50 | * |
||
51 | * @param WP_REST_Request $request The API request object. |
||
52 | * @return array |
||
53 | */ |
||
54 | public function get_boxes( $request ) { |
||
71 | |||
72 | /** |
||
73 | * Get all public fields |
||
74 | * |
||
75 | * @since 2.2.0 |
||
76 | * |
||
77 | * @param WP_REST_Request $request The API request object. |
||
78 | * @return array |
||
79 | */ |
||
80 | public function get_box( $request ) { |
||
91 | } |
||
92 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.