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 SubscriptionsTest extends AbstractAPITest |
||
9 | { |
||
10 | protected static $planId; |
||
11 | |||
12 | protected static $productId; |
||
13 | |||
14 | protected $plan = array( |
||
15 | 'name' => array( |
||
16 | 'en' => 'Subscription Plan Name', |
||
17 | ), |
||
18 | 'group_id' => 'group_id', |
||
19 | 'charge' => array( |
||
20 | 'amount' => 1, |
||
21 | 'currency' => 'USD', |
||
22 | 'period' => array( |
||
23 | 'value' => 1, |
||
24 | 'type' => 'month', |
||
25 | ), |
||
26 | ), |
||
27 | 'expiration' => array( |
||
28 | 'value' => 3, |
||
29 | 'type' => 'month', |
||
30 | ), |
||
31 | ); |
||
32 | |||
33 | protected $product = array( |
||
34 | 'name' => 'Product Name', |
||
35 | 'group_id' => 'group_id', |
||
36 | ); |
||
37 | |||
38 | public function testCreateSubscriptionPlan() |
||
48 | |||
49 | /** |
||
50 | * @depends testCreateSubscriptionPlan |
||
51 | */ |
||
52 | View Code Duplication | public function testListSubscriptionPlans() |
|
|
|||
53 | { |
||
54 | $response = static::$xsollaClient->ListSubscriptionPlans(array( |
||
55 | 'project_id' => static::$projectId, |
||
56 | 'limit' => 100, |
||
57 | )); |
||
58 | static::assertInternalType('array', $response); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @depends testListSubscriptionPlans |
||
63 | */ |
||
64 | public function testUpdateSubscriptionPlan() |
||
73 | |||
74 | /** |
||
75 | * @depends testUpdateSubscriptionPlan |
||
76 | */ |
||
77 | public function testDisableSubscriptionPlan() |
||
84 | |||
85 | /** |
||
86 | * @depends testDisableSubscriptionPlan |
||
87 | */ |
||
88 | public function testEnableSubscriptionPlan() |
||
95 | |||
96 | /** |
||
97 | * @depends testEnableSubscriptionPlan |
||
98 | */ |
||
99 | public function testDeleteSubscriptionPlan() |
||
106 | |||
107 | /** |
||
108 | * @depends testDeleteSubscriptionPlan |
||
109 | */ |
||
110 | View Code Duplication | public function testCreateSubscriptionProduct() |
|
119 | |||
120 | /** |
||
121 | * @depends testCreateSubscriptionProduct |
||
122 | */ |
||
123 | View Code Duplication | public function testListSubscriptionPlansWithParams() |
|
135 | |||
136 | /** |
||
137 | * @depends testCreateSubscriptionProduct |
||
138 | */ |
||
139 | View Code Duplication | public function testUpdateSubscriptionProduct() |
|
148 | |||
149 | /** |
||
150 | * @depends testUpdateSubscriptionProduct |
||
151 | */ |
||
152 | public function testDeleteSubscriptionProduct() |
||
159 | |||
160 | public function testListSubscriptionProducts() |
||
167 | |||
168 | public function testListSubscriptionProductsWithParams() |
||
176 | |||
177 | public function testUpdateSubscription() |
||
181 | |||
182 | View Code Duplication | public function testListSubscriptions() |
|
190 | |||
191 | View Code Duplication | public function testListSubscriptionWithParams() |
|
201 | |||
202 | View Code Duplication | public function testListUserSubscriptionPayments() |
|
210 | |||
211 | public function testListSubscriptionPayments() |
||
218 | |||
219 | public function testListSubscriptionCurrencies() |
||
226 | } |
||
227 |
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.