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 |
||
| 13 | class Grunion_Contact_Form_Endpoint extends WP_REST_Posts_Controller { |
||
| 14 | /** |
||
| 15 | * Check whether a given request has proper authorization to view feedback items. |
||
| 16 | * |
||
| 17 | * @param WP_REST_Request $request Full details about the request. |
||
| 18 | * @return WP_Error|boolean |
||
| 19 | */ |
||
| 20 | View Code Duplication | public function get_items_permissions_check( $request ) { |
|
| 31 | |||
| 32 | /** |
||
| 33 | * Check whether a given request has proper authorization to view feedback item. |
||
| 34 | * |
||
| 35 | * @param WP_REST_Request $request Full details about the request. |
||
| 36 | * @return WP_Error|boolean |
||
| 37 | */ |
||
| 38 | View Code Duplication | public function get_item_permissions_check( $request ) { |
|
| 49 | |||
| 50 | } |
||
| 51 | |||
| 53 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.