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 |
||
39 | View Code Duplication | class NopeClient extends \yii\authclient\OAuth2 |
|
|
|||
40 | { |
||
41 | /** |
||
42 | * Site for urls generation. |
||
43 | */ |
||
44 | public $site; |
||
45 | |||
46 | public function buildUrl($path, array $params = []) |
||
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | public function buildAuthUrl(array $params = []) |
||
62 | |||
63 | /** |
||
64 | * Inits Urls based on $site. |
||
65 | */ |
||
66 | public function init() |
||
86 | |||
87 | /** {@inheritdoc} */ |
||
88 | protected function initUserAttributes() |
||
92 | |||
93 | /** {@inheritdoc} */ |
||
94 | protected function apiInternal($accessToken, $url, $method, array $params, array $headers) |
||
103 | |||
104 | /** {@inheritdoc} */ |
||
105 | protected function defaultName() |
||
109 | |||
110 | /** {@inheritdoc} */ |
||
111 | protected function defaultTitle() |
||
115 | |||
116 | /** |
||
117 | * {@inheritdoc} |
||
118 | */ |
||
119 | public function setState($key, $value) |
||
123 | |||
124 | /** |
||
125 | * {@inheritdoc} |
||
126 | */ |
||
127 | public function getState($key) |
||
131 | |||
132 | /** |
||
133 | * {@inheritdoc} |
||
134 | */ |
||
135 | public function removeState($key) |
||
139 | } |
||
140 |
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.