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 |
||
9 | View Code Duplication | class ConversationsMessage extends Entity |
|
|
|||
10 | { |
||
11 | |||
12 | /** |
||
13 | * Fields that can be mass assigned using newEntity() or patchEntity(). |
||
14 | * |
||
15 | * @var array |
||
16 | */ |
||
17 | protected $_accessible = [ |
||
18 | '*' => true, |
||
19 | 'id' => false, |
||
20 | ]; |
||
21 | |||
22 | /** |
||
23 | * Purify the message for display the message. |
||
24 | * |
||
25 | * @param string $content The message to be purified. |
||
26 | * |
||
27 | * @return string |
||
28 | */ |
||
29 | protected function _getMessage($content) |
||
38 | |||
39 | /** |
||
40 | * Purify the message for display the message. |
||
41 | * |
||
42 | * @return string |
||
43 | */ |
||
44 | protected function _getMessageEmpty() |
||
53 | } |
||
54 |
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.