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 |
||
10 | class WorkWeb extends AbstractAuthentication |
||
11 | { |
||
12 | const AUTH_URL = 'https://open.work.weixin.qq.com/wwopen/sso/qrConnect'; |
||
13 | const API_GET_USER_INFO = 'https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo'; |
||
14 | |||
15 | /** |
||
16 | * Indicates if the session state should be utilized. |
||
17 | * |
||
18 | * @var bool |
||
19 | */ |
||
20 | protected $stateless = true; |
||
21 | |||
22 | /** |
||
23 | * {@inheritdoc}. |
||
24 | */ |
||
25 | protected function getAuthUrl($state) |
||
29 | |||
30 | /** |
||
31 | * {@inheritdoc}. |
||
32 | */ |
||
33 | protected function buildAuthUrlFromBase($url, $state) |
||
39 | |||
40 | /** |
||
41 | * {@inheritdoc}. |
||
42 | */ |
||
43 | protected function getCodeFields($state = null) |
||
51 | |||
52 | /** |
||
53 | * @param null $code |
||
54 | * |
||
55 | * @throws InvalidStateException |
||
56 | * |
||
57 | * @return \EntWeChat\Support\Collection |
||
58 | */ |
||
59 | View Code Duplication | public function user($code = null) |
|
71 | } |
||
72 |
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.