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 |
||
| 18 | View Code Duplication | class Capability extends ApiResource |
|
|
|
|||
| 19 | { |
||
| 20 | |||
| 21 | const OBJECT_NAME = "capability"; |
||
| 22 | |||
| 23 | use ApiOperations\Update; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Possible string representations of a capability's status. |
||
| 27 | * @link https://stripe.com/docs/api/capabilities/object#capability_object-status |
||
| 28 | */ |
||
| 29 | const STATUS_ACTIVE = 'active'; |
||
| 30 | const STATUS_INACTIVE = 'inactive'; |
||
| 31 | const STATUS_PENDING = 'pending'; |
||
| 32 | const STATUS_UNREQUESTED = 'unrequested'; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @return string The API URL for this Stripe account reversal. |
||
| 36 | */ |
||
| 37 | public function instanceUrl() |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param array|string $_id |
||
| 59 | * @param array|string|null $_opts |
||
| 60 | * |
||
| 61 | * @throws \Stripe\Error\InvalidRequest |
||
| 62 | */ |
||
| 63 | public static function retrieve($_id, $_opts = null) |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @param string $_id |
||
| 72 | * @param array|null $_params |
||
| 73 | * @param array|string|null $_options |
||
| 74 | * |
||
| 75 | * @throws \Stripe\Error\InvalidRequest |
||
| 76 | */ |
||
| 77 | public static function update($_id, $_params = null, $_options = null) |
||
| 83 | } |
||
| 84 |
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.