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 |
||
| 29 | class QRCode extends AbstractAPI |
||
| 30 | { |
||
| 31 | const DAY = 86400; |
||
| 32 | const SCENE_MAX_VALUE = 100000; |
||
| 33 | const SCENE_QR_CARD = 'QR_CARD'; |
||
| 34 | const SCENE_QR_TEMPORARY = 'QR_SCENE'; |
||
| 35 | const SCENE_QR_TEMPORARY_STR = 'QR_STR_SCENE'; |
||
| 36 | const SCENE_QR_FOREVER = 'QR_LIMIT_SCENE'; |
||
| 37 | const SCENE_QR_FOREVER_STR = 'QR_LIMIT_STR_SCENE'; |
||
| 38 | |||
| 39 | const API_CREATE = 'https://api.weixin.qq.com/cgi-bin/qrcode/create'; |
||
| 40 | const API_SHOW = 'https://mp.weixin.qq.com/cgi-bin/showqrcode'; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Create forever. |
||
| 44 | * |
||
| 45 | * @param int $sceneValue |
||
| 46 | * |
||
| 47 | * @return \EasyWeChat\Support\Collection |
||
| 48 | */ |
||
| 49 | 1 | View Code Duplication | public function forever($sceneValue) |
| 63 | |||
| 64 | /** |
||
| 65 | * Create temporary. |
||
| 66 | * |
||
| 67 | * @param string $sceneValue |
||
| 68 | * @param null $expireSeconds |
||
| 69 | * |
||
| 70 | * @return \EasyWeChat\Support\Collection |
||
| 71 | */ |
||
| 72 | 1 | View Code Duplication | public function temporary($sceneValue, $expireSeconds = null) |
| 86 | |||
| 87 | /** |
||
| 88 | * Create QRCode for card. |
||
| 89 | * |
||
| 90 | * @param array $card |
||
| 91 | * |
||
| 92 | * { |
||
| 93 | * "card_id": "pFS7Fjg8kV1IdDz01r4SQwMkuCKc", |
||
| 94 | * "code": "198374613512", |
||
| 95 | * "openid": "oFS7Fjl0WsZ9AMZqrI80nbIq8xrA", |
||
| 96 | * "expire_seconds": "1800", |
||
| 97 | * "is_unique_code": false , "outer_id" : 1 |
||
| 98 | * } |
||
| 99 | * |
||
| 100 | * @return \EasyWeChat\Support\Collection |
||
| 101 | */ |
||
| 102 | 1 | public function card($card) |
|
| 106 | |||
| 107 | /** |
||
| 108 | * Return url for ticket. |
||
| 109 | * |
||
| 110 | * @param string $ticket |
||
| 111 | * |
||
| 112 | * @return string |
||
| 113 | */ |
||
| 114 | 1 | public function url($ticket) |
|
| 118 | |||
| 119 | /** |
||
| 120 | * Create a QRCode. |
||
| 121 | * |
||
| 122 | * @param string $actionName |
||
| 123 | * @param array $actionInfo |
||
| 124 | * @param bool $temporary |
||
| 125 | * @param int $expireSeconds |
||
| 126 | * |
||
| 127 | * @return \EasyWeChat\Support\Collection |
||
| 128 | */ |
||
| 129 | 3 | protected function create($actionName, $actionInfo, $temporary = true, $expireSeconds = null) |
|
| 144 | } |
||
| 145 |