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 |
||
| 25 | View Code Duplication | class Dispute extends ApiResource |
|
|
|
|||
| 26 | { |
||
| 27 | |||
| 28 | const OBJECT_NAME = "dispute"; |
||
| 29 | |||
| 30 | use ApiOperations\All; |
||
| 31 | use ApiOperations\Retrieve; |
||
| 32 | use ApiOperations\Update; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Possible string representations of dispute reasons. |
||
| 36 | * @link https://stripe.com/docs/api#dispute_object |
||
| 37 | */ |
||
| 38 | const REASON_BANK_CANNOT_PROCESS = 'bank_cannot_process'; |
||
| 39 | const REASON_CHECK_RETURNED = 'check_returned'; |
||
| 40 | const REASON_CREDIT_NOT_PROCESSED = 'credit_not_processed'; |
||
| 41 | const REASON_CUSTOMER_INITIATED = 'customer_initiated'; |
||
| 42 | const REASON_DEBIT_NOT_AUTHORIZED = 'debit_not_authorized'; |
||
| 43 | const REASON_DUPLICATE = 'duplicate'; |
||
| 44 | const REASON_FRAUDULENT = 'fraudulent'; |
||
| 45 | const REASON_GENERAL = 'general'; |
||
| 46 | const REASON_INCORRECT_ACCOUNT_DETAILS = 'incorrect_account_details'; |
||
| 47 | const REASON_INSUFFICIENT_FUNDS = 'insufficient_funds'; |
||
| 48 | const REASON_PRODUCT_NOT_RECEIVED = 'product_not_received'; |
||
| 49 | const REASON_PRODUCT_UNACCEPTABLE = 'product_unacceptable'; |
||
| 50 | const REASON_SUBSCRIPTION_CANCELED = 'subscription_canceled'; |
||
| 51 | const REASON_UNRECOGNIZED = 'unrecognized'; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Possible string representations of dispute statuses. |
||
| 55 | * @link https://stripe.com/docs/api#dispute_object |
||
| 56 | */ |
||
| 57 | const STATUS_CHARGE_REFUNDED = 'charge_refunded'; |
||
| 58 | const STATUS_LOST = 'lost'; |
||
| 59 | const STATUS_NEEDS_RESPONSE = 'needs_response'; |
||
| 60 | const STATUS_UNDER_REVIEW = 'under_review'; |
||
| 61 | const STATUS_WARNING_CLOSED = 'warning_closed'; |
||
| 62 | const STATUS_WARNING_NEEDS_RESPONSE = 'warning_needs_response'; |
||
| 63 | const STATUS_WARNING_UNDER_REVIEW = 'warning_under_review'; |
||
| 64 | const STATUS_WON = 'won'; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param array|string|null $options |
||
| 68 | * |
||
| 69 | * @return Dispute The closed dispute. |
||
| 70 | */ |
||
| 71 | public function close($options = null) |
||
| 78 | } |
||
| 79 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.