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 | class SendSmsTest extends \Codeception\Test\Unit |
||
|
|||
12 | { |
||
13 | /** |
||
14 | * @var \UnitTester |
||
15 | */ |
||
16 | protected $tester; |
||
17 | protected $phoneNumber = '639989764990'; |
||
18 | protected $message = 'Unit Testing for SendSmsTest'; |
||
19 | |||
20 | protected function _before() |
||
23 | |||
24 | protected function _after() |
||
27 | |||
28 | View Code Duplication | protected function sendSuccess(SmsProviderServicesInterface $provider) |
|
50 | |||
51 | View Code Duplication | protected function sendFail(SmsProviderServicesInterface $provider) |
|
73 | |||
74 | // Send via PromoTexter Success |
||
75 | public function testSendViaPromoTexterSuccess() |
||
81 | |||
82 | // Send via PromoTexter Fail (Incorrect Phone Number Format) |
||
83 | public function testSendViaPromoTexterFail() |
||
89 | |||
90 | // Send via RisingTide Success |
||
91 | public function testSendViaRisingTideSuccess() |
||
96 | |||
97 | // Send via RisingTide Fail |
||
98 | public function testSendViaRisingTideFail() |
||
104 | |||
105 | // Send via Semaphore Success |
||
106 | public function testSendViaSemaphoreSuccess() |
||
111 | |||
112 | // Send via Semaphore Fail |
||
113 | public function testSendViaSemaphoreFail() |
||
119 | |||
120 | // Send via Chikka Success |
||
121 | public function testSendViaChikkaSuccess() |
||
126 | |||
127 | // Send via Chikka Fail |
||
128 | public function testSendViaChikkaFail() |
||
134 | |||
135 | // Send via Chikka Success |
||
136 | public function testSendViaNexmoSuccess() |
||
141 | |||
142 | // Send via Nexmo Fail |
||
143 | public function testSendViaNexmoFail() |
||
149 | |||
150 | // Send via Twilio Success |
||
151 | public function testSendViaTwilioSuccess() |
||
156 | |||
157 | // Send via Nexmo Fail |
||
158 | public function testSendViaTwilioFail() |
||
164 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.