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 | View Code Duplication | class Balance extends AbstractResource |
|
|
|||
12 | { |
||
13 | /** |
||
14 | * API resource name. |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | const RESOURCE_NAME = 'balance'; |
||
19 | |||
20 | /** |
||
21 | * Retrieve a merchant's balance. |
||
22 | * |
||
23 | * @return stdClass |
||
24 | */ |
||
25 | public static function balance() |
||
29 | |||
30 | /** |
||
31 | * Not avalable for this resource. |
||
32 | * |
||
33 | * @throws Everypay\Exception\RuntimeException |
||
34 | */ |
||
35 | public static function create(array $params) |
||
42 | |||
43 | /** |
||
44 | * Not avalable for this resource. |
||
45 | * |
||
46 | * @throws Everypay\Exception\RuntimeException |
||
47 | */ |
||
48 | public static function update($token, array $params) |
||
55 | |||
56 | /** |
||
57 | * Not avalable for this resource. |
||
58 | * |
||
59 | * @throws Everypay\Exception\RuntimeException |
||
60 | */ |
||
61 | public static function delete($token, array $params = array()) |
||
68 | } |
||
69 |
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.