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 StasisStart extends Event implements IdentifiableEventInterface |
|
|
|||
30 | { |
||
31 | /** |
||
32 | * @var array Arguments to the application |
||
33 | */ |
||
34 | private $args; |
||
35 | |||
36 | /** |
||
37 | * @var Channel |
||
38 | */ |
||
39 | private $channel; |
||
40 | |||
41 | /** |
||
42 | * @var Channel (optional) |
||
43 | */ |
||
44 | private $replaceChannel; |
||
45 | |||
46 | /** |
||
47 | * @return array Arguments to the application |
||
48 | */ |
||
49 | public function getArgs() |
||
53 | |||
54 | /** |
||
55 | * @return Channel |
||
56 | */ |
||
57 | 22 | public function getChannel() |
|
61 | |||
62 | /** |
||
63 | * @return Channel (optional) |
||
64 | */ |
||
65 | public function getReplaceChannel() |
||
69 | |||
70 | 22 | public function getEventId() |
|
74 | |||
75 | /** |
||
76 | * @param AriClient $client |
||
77 | * @param string $response |
||
78 | */ |
||
79 | 22 | public function __construct(AriClient $client, $response) |
|
88 | |||
89 | } |
||
90 |
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.