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 |
||
| 23 | class AliyunGateway extends Gateway |
||
| 24 | { |
||
| 25 | use HasHttpRequest; |
||
| 26 | |||
| 27 | const ENDPOINT_URL = 'http://dysmsapi.aliyuncs.com'; |
||
| 28 | const ENDPOINT_METHOD = 'SendSms'; |
||
| 29 | const ENDPOINT_VERSION = '2017-05-25'; |
||
| 30 | const ENDPOINT_FORMAT = 'JSON'; |
||
| 31 | const ENDPOINT_REGION_ID = 'cn-hangzhou'; |
||
| 32 | const ENDPOINT_SIGNATURE_METHOD = 'HMAC-SHA1'; |
||
| 33 | const ENDPOINT_SIGNATURE_VERSION = '1.0'; |
||
| 34 | |||
| 35 | 1 | public function __construct(array $config) |
|
| 40 | |||
| 41 | /** |
||
| 42 | * @param array|int|string $to |
||
| 43 | * @param \Overtrue\EasySms\Contracts\MessageInterface $message |
||
| 44 | * @param \Overtrue\EasySms\Support\Config $config |
||
| 45 | * |
||
| 46 | * @return array |
||
| 47 | * |
||
| 48 | * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException; |
||
| 49 | */ |
||
| 50 | 1 | public function send($to, MessageInterface $message, Config $config) |
|
| 78 | |||
| 79 | /** |
||
| 80 | * Generate Sign. |
||
| 81 | * |
||
| 82 | * @param array $params |
||
| 83 | * |
||
| 84 | * @return string |
||
| 85 | */ |
||
| 86 | 1 | protected function generateSign($params) |
|
| 94 | |||
| 95 | /** |
||
| 96 | * @return false|string |
||
| 97 | */ |
||
| 98 | 1 | protected function getTimestamp() |
|
| 107 | } |
||
| 108 |
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.