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 ChannelDialplan extends Event implements IdentifiableEventInterface |
|
|
|||
30 | { |
||
31 | /** |
||
32 | * @var Channel |
||
33 | */ |
||
34 | private $channel; |
||
35 | |||
36 | /** |
||
37 | * @var string The application about to be executed. |
||
38 | */ |
||
39 | private $dialplanApp; |
||
40 | |||
41 | /** |
||
42 | * @var string The data to be passed to the application. |
||
43 | */ |
||
44 | private $dialplanAppData; |
||
45 | |||
46 | /** |
||
47 | * @return Channel |
||
48 | */ |
||
49 | public function getChannel() |
||
53 | |||
54 | /** |
||
55 | * @return string The application about to be executed. |
||
56 | */ |
||
57 | public function getDialplanApp() |
||
61 | |||
62 | /** |
||
63 | * @return string The data to be passed to the application. |
||
64 | */ |
||
65 | public function getDialplanAppData() |
||
69 | |||
70 | public function getEventId() |
||
74 | |||
75 | /** |
||
76 | * @param AriClient $client |
||
77 | * @param string $response |
||
78 | */ |
||
79 | 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.