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 |
||
16 | class MoMoTest extends TestCase |
||
17 | { |
||
18 | |||
19 | /** |
||
20 | * @var \yiiviet\payment\momo\PaymentGateway |
||
21 | */ |
||
22 | public $gateway; |
||
23 | |||
24 | public static function gatewayId(): string |
||
28 | |||
29 | public function testPurchase() |
||
46 | |||
47 | /** |
||
48 | * @expectedException \yii\base\InvalidConfigException |
||
49 | * @expectedExceptionMessage cannot be blank |
||
50 | * @depends testPurchase |
||
51 | */ |
||
52 | public function testInvalidPurchase() |
||
56 | |||
57 | /** |
||
58 | * @depends testPurchase |
||
59 | */ |
||
60 | public function testQueryDR() |
||
70 | |||
71 | /** |
||
72 | * @expectedException \yii\base\InvalidConfigException |
||
73 | * @expectedExceptionMessage cannot be blank |
||
74 | * @depends testQueryDR |
||
75 | */ |
||
76 | public function testInvalidQueryDR() |
||
80 | |||
81 | /** |
||
82 | * @depends testPurchase |
||
83 | * @depends testQueryDR |
||
84 | */ |
||
85 | View Code Duplication | public function testRefund() |
|
97 | |||
98 | /** |
||
99 | * @expectedException \yii\base\InvalidConfigException |
||
100 | * @expectedExceptionMessage cannot be blank |
||
101 | * @depends testRefund |
||
102 | */ |
||
103 | public function testInvalidRefund() |
||
107 | |||
108 | /** |
||
109 | * @depends testRefund |
||
110 | */ |
||
111 | View Code Duplication | public function testQueryRefund() |
|
123 | |||
124 | |||
125 | /** |
||
126 | * @expectedException \yii\base\InvalidConfigException |
||
127 | * @expectedExceptionMessage cannot be blank |
||
128 | * @depends testQueryRefund |
||
129 | */ |
||
130 | public function testInvalidQueryRefund() |
||
134 | |||
135 | /** |
||
136 | * @depends testPurchase |
||
137 | * @depends testQueryDR |
||
138 | */ |
||
139 | public function testVerifyRequestPurchaseSuccess() |
||
144 | |||
145 | /** |
||
146 | * @depends testPurchase |
||
147 | * @depends testQueryDR |
||
148 | */ |
||
149 | public function testVerifyRequestIPN() |
||
155 | } |
||
156 |
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.