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 |
||
19 | View Code Duplication | class AccountCombo extends Combo |
|
|
|||
20 | { |
||
21 | /** {@inheritdoc} */ |
||
22 | public $type = 'hosting/account'; |
||
23 | |||
24 | /** {@inheritdoc} */ |
||
25 | public $name = 'login'; |
||
26 | |||
27 | /** {@inheritdoc} */ |
||
28 | public $url = '/hosting/account/index'; |
||
29 | |||
30 | /** {@inheritdoc} */ |
||
31 | public $_return = ['id', 'client', 'client_id', 'device', 'device_id', 'account']; |
||
32 | |||
33 | /** {@inheritdoc} */ |
||
34 | public $_rename = ['text' => 'login']; |
||
35 | |||
36 | /** |
||
37 | * @var string the type of client |
||
38 | * Used by [[getFilter]] to generate filter |
||
39 | * |
||
40 | * @see getFilter() |
||
41 | */ |
||
42 | public $accountType; |
||
43 | |||
44 | /** {@inheritdoc} */ |
||
45 | public function getFilter() |
||
53 | |||
54 | /** {@inheritdoc} */ |
||
55 | public function getPluginOptions($options = []) |
||
66 | } |
||
67 |
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.