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 |
||
| 31 | View Code Duplication | class Payout extends ApiResource |
|
|
|
|||
| 32 | { |
||
| 33 | |||
| 34 | const OBJECT_NAME = "payout"; |
||
| 35 | |||
| 36 | use ApiOperations\All; |
||
| 37 | use ApiOperations\Create; |
||
| 38 | use ApiOperations\Retrieve; |
||
| 39 | use ApiOperations\Update; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Types of payout failure codes. |
||
| 43 | * @link https://stripe.com/docs/api#payout_failures |
||
| 44 | */ |
||
| 45 | const FAILURE_ACCOUNT_CLOSED = 'account_closed'; |
||
| 46 | const FAILURE_ACCOUNT_FROZEN = 'account_frozen'; |
||
| 47 | const FAILURE_BANK_ACCOUNT_RESTRICTED = 'bank_account_restricted'; |
||
| 48 | const FAILURE_BANK_OWNERSHIP_CHANGED = 'bank_ownership_changed'; |
||
| 49 | const FAILURE_COULD_NOT_PROCESS = 'could_not_process'; |
||
| 50 | const FAILURE_DEBIT_NOT_AUTHORIZED = 'debit_not_authorized'; |
||
| 51 | const FAILURE_DECLINED = 'declined'; |
||
| 52 | const FAILURE_INCORRECT_ACCOUNT_HOLDER_NAME = 'incorrect_account_holder_name'; |
||
| 53 | const FAILURE_INSUFFICIENT_FUNDS = 'insufficient_funds'; |
||
| 54 | const FAILURE_INVALID_ACCOUNT_NUMBER = 'invalid_account_number'; |
||
| 55 | const FAILURE_INVALID_CURRENCY = 'invalid_currency'; |
||
| 56 | const FAILURE_NO_ACCOUNT = 'no_account'; |
||
| 57 | const FAILURE_UNSUPPORTED_CARD = 'unsupported_card'; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Possible string representations of the payout methods. |
||
| 61 | * @link https://stripe.com/docs/api/payouts/object#payout_object-method |
||
| 62 | */ |
||
| 63 | const METHOD_STANDARD = 'standard'; |
||
| 64 | const METHOD_INSTANT = 'instant'; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Possible string representations of the status of the payout. |
||
| 68 | * @link https://stripe.com/docs/api/payouts/object#payout_object-status |
||
| 69 | */ |
||
| 70 | const STATUS_CANCELED = 'canceled'; |
||
| 71 | const STATUS_IN_TRANSIT = 'in_transit'; |
||
| 72 | const STATUS_FAILED = 'failed'; |
||
| 73 | const STATUS_PAID = 'paid'; |
||
| 74 | const STATUS_PENDING = 'pending'; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Possible string representations of the type of payout. |
||
| 78 | * @link https://stripe.com/docs/api/payouts/object#payout_object-type |
||
| 79 | */ |
||
| 80 | const TYPE_BANK_ACCOUNT = 'bank_account'; |
||
| 81 | const TYPE_CARD = 'card'; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @return Payout The canceled payout. |
||
| 85 | */ |
||
| 86 | public function cancel() |
||
| 93 | } |
||
| 94 |
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.