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 SmsBaoAgent extends Agent implements ContentSms |
||
12 | { |
||
13 | protected $resultArr = [ |
||
14 | '0' => '发送成功', |
||
15 | '-1' => '参数不全', |
||
16 | '30' => '密码错误', |
||
17 | '40' => '账号不存在', |
||
18 | '41' => '余额不足', |
||
19 | '42' => '帐户已过期', |
||
20 | '43' => 'IP地址限制', |
||
21 | '50' => '内容含有敏感词', |
||
22 | '51' => '手机号码不正确', |
||
23 | ]; |
||
24 | |||
25 | public function sendSms($to, $content, $tempId, array $data) |
||
29 | |||
30 | View Code Duplication | public function sendContentSms($to, $content) |
|
42 | |||
43 | View Code Duplication | public function voiceVerify($to, $code, $tempId, array $tempData) |
|
55 | |||
56 | protected function setResult($result) |
||
68 | } |
||
69 |
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.