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 |
||
44 | class User extends Entity |
||
45 | { |
||
46 | |||
47 | /** |
||
48 | * List of computed or virtual fields that **should** be included in JSON or array |
||
49 | * representations of this Entity. If a field is present in both _hidden and _virtual |
||
50 | * the field will **not** be in the array/json versions of the entity. |
||
51 | * |
||
52 | * @var array |
||
53 | */ |
||
54 | protected $_virtual = [ |
||
55 | 'activation_url', |
||
56 | 'setup_password_url' |
||
57 | ]; |
||
58 | |||
59 | /** |
||
60 | * Set virtual field activation_url. |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | View Code Duplication | protected function _getActivationUrl() |
|
74 | |||
75 | /** |
||
76 | * set virtual field setup_password_url |
||
77 | * |
||
78 | * @return string |
||
79 | */ |
||
80 | View Code Duplication | protected function _getSetupPasswordUrl() |
|
90 | |||
91 | /** |
||
92 | * Setup password. |
||
93 | * |
||
94 | * @param string $password User password for create hashed. |
||
95 | * @return null|string |
||
96 | */ |
||
97 | protected function _setPassword($password) |
||
105 | } |
||
106 |
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.