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 |
||
| 16 | class WPCOM_REST_API_V2_Endpoint_Search extends WP_REST_Controller { |
||
| 17 | /** |
||
| 18 | * Constructor. |
||
| 19 | */ |
||
| 20 | public function __construct() { |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Called automatically on `rest_api_init()`. |
||
| 29 | */ |
||
| 30 | View Code Duplication | public function register_routes() { |
|
| 43 | |||
| 44 | /** |
||
| 45 | * Returns search results for the current blog. |
||
| 46 | * |
||
| 47 | * @param WP_REST_Request $request The REST API request data. |
||
| 48 | * @return mixed The REST API response from public-api. |
||
| 49 | */ |
||
| 50 | View Code Duplication | public function get_search_results( $request ) { |
|
| 69 | } |
||
| 70 | |||
| 72 |
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.