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 WC_REST_Settings_API_Controller extends WC_REST_Controller { | ||
| 17 | |||
| 18 | /** | ||
| 19 | * Route base. | ||
| 20 | * | ||
| 21 | * @var string | ||
| 22 | */ | ||
| 23 | protected $rest_base = 'settings'; | ||
| 24 | |||
| 25 | /** | ||
| 26 | * Makes sure the current user has access to the settings APIs. | ||
| 27 | * | ||
| 28 | * @since 2.7.0 | ||
| 29 | * @param WP_REST_Request $request Full details about the request. | ||
| 30 | * @return WP_Error|boolean | ||
| 31 | */ | ||
| 32 | View Code Duplication | 	public function permissions_check( $request ) { | |
| 43 | |||
| 44 | /** | ||
| 45 | * Filters out bad values from the settings array/filter so we | ||
| 46 | * only return known values via the API. | ||
| 47 | * | ||
| 48 | * @since 2.7.0 | ||
| 49 | * @param array $setting | ||
| 50 | * @return array | ||
| 51 | */ | ||
| 52 | 	public function filter_setting( $setting ) { | ||
| 64 | |||
| 65 | /** | ||
| 66 | * Callback for allowed keys for each setting response. | ||
| 67 | * | ||
| 68 | * @since 2.7.0 | ||
| 69 | * @param string $key Key to check | ||
| 70 | * @return boolean | ||
| 71 | */ | ||
| 72 | 	public function allowed_setting_keys( $key ) { | ||
| 78 | |||
| 79 | /** | ||
| 80 | * Boolean for if a setting type is a valid supported setting type. | ||
| 81 | * | ||
| 82 | * @since 2.7.0 | ||
| 83 | * @param string $type | ||
| 84 | * @return boolean | ||
| 85 | */ | ||
| 86 | 	public function is_setting_type_valid( $type ) { | ||
| 93 | } | ||
| 94 | 
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.