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_Gateway_Paypal_API_Handler { |
||
| 12 | |||
| 13 | /** @var string API Username */ |
||
| 14 | public static $api_username; |
||
| 15 | |||
| 16 | /** @var string API Password */ |
||
| 17 | public static $api_password; |
||
| 18 | |||
| 19 | /** @var string API Signature */ |
||
| 20 | public static $api_signature; |
||
| 21 | |||
| 22 | /** @var string API Signature */ |
||
| 23 | public static $sandbox = false; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Get capture request args. |
||
| 27 | * See https://developer.paypal.com/docs/classic/api/merchant/DoCapture_API_Operation_NVP/. |
||
| 28 | * @param WC_Order $order |
||
| 29 | * @param float $amount |
||
| 30 | * @param string $reason |
||
|
|
|||
| 31 | * @return array |
||
| 32 | */ |
||
| 33 | public static function get_capture_request( $order, $amount = null ) { |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Get refund request args. |
||
| 50 | * @param WC_Order $order |
||
| 51 | * @param float $amount |
||
| 52 | * @param string $reason |
||
| 53 | * @return array |
||
| 54 | */ |
||
| 55 | public static function get_refund_request( $order, $amount = null, $reason = '' ) { |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Capture an authorization. |
||
| 76 | * @param WC_Order $order |
||
| 77 | * @param float $amount |
||
| 78 | * @return object Either an object of name value pairs for a success, or a WP_ERROR object. |
||
| 79 | */ |
||
| 80 | View Code Duplication | public static function do_capture( $order, $amount = null ) { |
|
| 104 | |||
| 105 | /** |
||
| 106 | * Refund an order via PayPal. |
||
| 107 | * @param WC_Order $order |
||
| 108 | * @param float $amount |
||
| 109 | * @param string $reason |
||
| 110 | * @return object Either an object of name value pairs for a success, or a WP_ERROR object. |
||
| 111 | */ |
||
| 112 | View Code Duplication | public static function refund_transaction( $order, $amount = null, $reason = '' ) { |
|
| 136 | } |
||
| 137 | |||
| 158 |
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.