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 |
||
| 11 | class WC_Stripe_API { |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Stripe API Endpoint |
||
| 15 | */ |
||
| 16 | const ENDPOINT = 'https://api.stripe.com/v1/'; |
||
| 17 | const STRIPE_API_VERSION = '2017-12-14'; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Secret API Key. |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | private static $secret_key = ''; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Set secret API Key. |
||
| 27 | * @param string $key |
||
|
|
|||
| 28 | */ |
||
| 29 | public static function set_secret_key( $secret_key ) { |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Get secret key. |
||
| 35 | * @return string |
||
| 36 | */ |
||
| 37 | public static function get_secret_key() { |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Generates the user agent we use to pass to API request so |
||
| 50 | * Stripe can identify our application. |
||
| 51 | * |
||
| 52 | * @since 4.0.0 |
||
| 53 | * @version 4.0.0 |
||
| 54 | */ |
||
| 55 | public static function get_user_agent() { |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Generates the headers to pass to API request. |
||
| 73 | * |
||
| 74 | * @since 4.0.0 |
||
| 75 | * @version 4.0.0 |
||
| 76 | */ |
||
| 77 | public static function get_headers() { |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Send the request to Stripe's API |
||
| 91 | * |
||
| 92 | * @since 3.1.0 |
||
| 93 | * @version 4.0.0 |
||
| 94 | * @param array $request |
||
| 95 | * @param string $api |
||
| 96 | * @return array|WP_Error |
||
| 97 | */ |
||
| 98 | public static function request( $request, $api = 'charges', $method = 'POST' ) { |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Retrieve API endpoint. |
||
| 130 | * |
||
| 131 | * @since 4.0.0 |
||
| 132 | * @version 4.0.0 |
||
| 133 | * @param string $api |
||
| 134 | */ |
||
| 135 | public static function retrieve( $api ) { |
||
| 156 | } |
||
| 157 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.