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 VoiceProvider extends Provider |
||
17 | { |
||
18 | /** |
||
19 | * 返回短信接口必须的参数 |
||
20 | * @param $key |
||
21 | * @return array |
||
22 | */ |
||
23 | View Code Duplication | protected function getRequiredOptions($key) |
|
40 | |||
41 | /** |
||
42 | * 返回请求链接 |
||
43 | * |
||
44 | * @param Message $message |
||
45 | * @return string |
||
46 | * @throws \RuntimeException |
||
47 | */ |
||
48 | protected function getUrl(Message $message) |
||
54 | |||
55 | /** |
||
56 | * 返回请求短信接口时的 payload |
||
57 | * |
||
58 | * @param Message $message |
||
59 | * @return string |
||
60 | * @throws \RuntimeException |
||
61 | */ |
||
62 | protected function getRequestPayload(Message $message) |
||
72 | |||
73 | /** |
||
74 | * 获取短信供应商名称 |
||
75 | * |
||
76 | * @return string |
||
77 | */ |
||
78 | public function getName() |
||
82 | } |
||
83 |
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.