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 |
||
| 23 | View Code Duplication | class PaymentMethod extends ApiResource |
|
|
|
|||
| 24 | { |
||
| 25 | |||
| 26 | const OBJECT_NAME = "payment_method"; |
||
| 27 | |||
| 28 | use ApiOperations\All; |
||
| 29 | use ApiOperations\Create; |
||
| 30 | use ApiOperations\Retrieve; |
||
| 31 | use ApiOperations\Update; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param array|null $params |
||
| 35 | * @param array|string|null $opts |
||
| 36 | * |
||
| 37 | * @return PaymentMethod The attached payment method. |
||
| 38 | */ |
||
| 39 | public function attach($params = null, $opts = null) |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param array|null $params |
||
| 49 | * @param array|string|null $opts |
||
| 50 | * |
||
| 51 | * @return PaymentMethod The detached payment method. |
||
| 52 | */ |
||
| 53 | public function detach($params = null, $opts = null) |
||
| 60 | } |
||
| 61 |
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.