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 |
||
14 | class XWireless extends Sms |
||
15 | { |
||
16 | private $responseCodes = [ |
||
17 | 'OK' => 'Successful', |
||
18 | |||
19 | '2904' => 'SMS Sending Failed', |
||
20 | |||
21 | '2905' => 'Invalid username/password combination', |
||
22 | |||
23 | '2906' => 'Credit exhausted', |
||
24 | |||
25 | '2907' => 'Gateway unavailable', |
||
26 | |||
27 | '2908' => 'Invalid schedule date format', |
||
28 | |||
29 | '2909' => 'Unable to schedule', |
||
30 | |||
31 | '2910' => 'Username is empty', |
||
32 | |||
33 | '2911' => 'Password is empty', |
||
34 | |||
35 | '2912' => 'Recipient is empty', |
||
36 | |||
37 | '2913=Message is empty', |
||
38 | |||
39 | '2914=Sender is empty', |
||
40 | |||
41 | '2915' => 'One or more required fields are empty', |
||
42 | ]; |
||
43 | private $baseUrl = 'https://secure.xwireless.net/api/v2/'; |
||
44 | |||
45 | /** |
||
46 | * Class Constructor. |
||
47 | * @param null $message |
||
48 | */ |
||
49 | 1 | View Code Duplication | public function __construct($message = null) |
61 | |||
62 | public function getResponse() |
||
68 | |||
69 | /** |
||
70 | * @param null $text |
||
71 | * @return bool |
||
72 | */ |
||
73 | 1 | public function send($text = null): bool |
|
104 | } |
||
105 |
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.