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 |
||
29 | View Code Duplication | class ChannelVarset extends Event implements IdentifiableEventInterface |
|
|
|||
30 | { |
||
31 | /** |
||
32 | * @var Channel (optional) - The channel on which the variable was set. If missing, the variable is a global variable. |
||
33 | */ |
||
34 | private $channel; |
||
35 | |||
36 | /** |
||
37 | * @var string The new value of the variable. |
||
38 | */ |
||
39 | private $value; |
||
40 | |||
41 | /** |
||
42 | * @var string The variable that changed. |
||
43 | */ |
||
44 | private $variable; |
||
45 | |||
46 | /** |
||
47 | * @return Channel (optional) - The channel on which the variable was set. If missing, the variable is a global variable. |
||
48 | */ |
||
49 | 38 | public function getChannel() |
|
53 | |||
54 | /** |
||
55 | * @return string The new value of the variable. |
||
56 | */ |
||
57 | public function getValue() |
||
61 | |||
62 | /** |
||
63 | * @return string The variable that changed. |
||
64 | */ |
||
65 | public function getVariable() |
||
69 | |||
70 | 38 | public function getEventId() |
|
74 | |||
75 | /** |
||
76 | * @param AriClient $client |
||
77 | * @param string $response |
||
78 | */ |
||
79 | 38 | public function __construct(AriClient $client, $response) |
|
87 | } |
||
88 |
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.