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 QrcodeApi extends BaseApi |
||
12 | { |
||
13 | /** |
||
14 | * 创建临时二维码 - 场景值ID(Int) |
||
15 | * |
||
16 | * @param integer $scene_id [场景值ID] |
||
17 | * @param integer $expire_seconds [该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒] |
||
18 | * |
||
19 | * @return bool|array $res |
||
20 | */ |
||
21 | public function create($scene_id = 0, $expire_seconds = 30) |
||
49 | |||
50 | /** |
||
51 | * 创建永久二维码 - 场景值ID(Int) |
||
52 | * |
||
53 | * @param integer $scene_id [场景值ID] |
||
54 | * |
||
55 | * @return bool|array $res |
||
56 | */ |
||
57 | public function createLimitInt($scene_id = 0) |
||
78 | |||
79 | /** |
||
80 | * 创建永久二维码 - 场景值Str(Str) |
||
81 | * |
||
82 | * @param integer $scene_id [场景值ID] |
||
83 | * |
||
84 | * @return bool|array $res |
||
85 | */ |
||
86 | public function createLimitStr($scene_str = '') |
||
107 | |||
108 | /** |
||
109 | * 通过ticket换取二维码 |
||
110 | * |
||
111 | * @param string $ticket [获取的二维码ticket,凭借此ticket可以在有效时间内换取二维码。] |
||
112 | * |
||
113 | * @return string [是一张图片,可以直接展示或者下载] |
||
114 | */ |
||
115 | View Code Duplication | public function show($ticket = '') |
|
133 | } |
||
134 |
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.