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 |
||
8 | class WalletTest extends AbstractAPITest |
||
9 | { |
||
10 | protected static $virtualItemId; |
||
11 | protected static $virtualItemSku; |
||
12 | |||
13 | public function testCreateWalletUser() |
||
17 | |||
18 | View Code Duplication | public function testGetWalletUser() |
|
26 | |||
27 | public function testUpdateWalletUser() |
||
37 | |||
38 | View Code Duplication | public function testListWalletUsers() |
|
47 | |||
48 | View Code Duplication | public function testListWalletUsersWithParams() |
|
49 | { |
||
50 | $response = static::$xsollaClient->ListWalletUsers(array( |
||
51 | 'project_id' => static::$projectId, |
||
52 | 'limit' => 1, |
||
53 | 'offset' => 0, |
||
54 | 'user_requisites' => static::$userId, |
||
55 | )); |
||
56 | static::assertInternalType('array', $response); |
||
57 | } |
||
58 | |||
59 | View Code Duplication | public function testListWalletUserOperations() |
|
69 | |||
70 | View Code Duplication | public function testListWalletUserOperationsWithParams() |
|
71 | { |
||
72 | $response = static::$xsollaClient->ListWalletUserOperations(array( |
||
73 | 'project_id' => static::$projectId, |
||
74 | 'user_id' => static::$userId, |
||
75 | 'datetime_from' => '2015-01-01T00:00:00Z', |
||
76 | 'datetime_to' => '2016-01-01T00:00:00Z', |
||
77 | 'transaction_type' => 'payment', |
||
78 | )); |
||
79 | static::assertInternalType('array', $response); |
||
80 | } |
||
81 | |||
82 | View Code Duplication | public function testRechargeWalletUserBalance() |
|
94 | |||
95 | public function testAddVirtualItemToWalletUser() |
||
120 | |||
121 | /** |
||
122 | * @depends testAddVirtualItemToWalletUser |
||
123 | */ |
||
124 | View Code Duplication | public function testListWalletUserVirtualItems() |
|
134 | |||
135 | /** |
||
136 | * @depends testAddVirtualItemToWalletUser |
||
137 | */ |
||
138 | public function testDeleteVirtualItemFromWalletUser() |
||
159 | } |
||
160 |
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.