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 |
||
| 31 | class QRCode extends AbstractMiniProgram |
||
| 32 | { |
||
| 33 | const API_GET_WXACODE = 'https://api.weixin.qq.com/wxa/getwxacode'; |
||
| 34 | const API_GET_WXACODE_UNLIMIT = 'http://api.weixin.qq.com/wxa/getwxacodeunlimit'; |
||
| 35 | const API_CREATE_QRCODE = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode'; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Get WXACode. |
||
| 39 | * |
||
| 40 | * @param string $path |
||
| 41 | * @param int $width |
||
| 42 | * @param bool $autoColor |
||
| 43 | * @param array $lineColor |
||
| 44 | * |
||
| 45 | * @return \Psr\Http\Message\StreamInterface |
||
| 46 | */ |
||
| 47 | View Code Duplication | public function getWXACode($path, $width = 430, $autoColor = false, $lineColor = ['r' => 0, 'g' => 0, 'b' => 0]) |
|
| 58 | |||
| 59 | /** |
||
| 60 | * Get WXACode unlimit. |
||
| 61 | * |
||
| 62 | * @param string $scene |
||
| 63 | * @param int $width |
||
| 64 | * @param bool $autoColor |
||
| 65 | * @param array $lineColor |
||
| 66 | * |
||
| 67 | * @return \Psr\Http\Message\StreamInterface |
||
| 68 | */ |
||
| 69 | View Code Duplication | public function getWXACodeUnlimit($scene, $width = 430, $autoColor = false, $lineColor = ['r' => 0, 'g' => 0, 'b' => 0]) |
|
| 80 | |||
| 81 | /** |
||
| 82 | * Create QRCode. |
||
| 83 | * |
||
| 84 | * @param string $path |
||
| 85 | * @param int $width |
||
| 86 | * |
||
| 87 | * @return \Psr\Http\Message\StreamInterface |
||
| 88 | */ |
||
| 89 | public function createQRCode($path, $width = 430) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Get stream. |
||
| 96 | * |
||
| 97 | * @param string $endpoint |
||
| 98 | * @param array $params |
||
| 99 | * |
||
| 100 | * @return \Psr\Http\Message\StreamInterface |
||
| 101 | */ |
||
| 102 | protected function getStream($endpoint, $params) |
||
| 106 | } |
||
| 107 |