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 |
||
7 | class Content extends Entity |
||
8 | { |
||
9 | /** |
||
10 | * @param array $array |
||
11 | */ |
||
12 | public function __construct(array $array = []) |
||
18 | |||
19 | /** |
||
20 | * @param string $id |
||
21 | * |
||
22 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
23 | * |
||
24 | * @return \Acquia\LiftClient\Entity\Content |
||
25 | */ |
||
26 | View Code Duplication | public function setId($id) |
|
35 | |||
36 | /** |
||
37 | * Gets the 'id' parameter. |
||
38 | * |
||
39 | * @return string |
||
40 | */ |
||
41 | public function getId() |
||
45 | |||
46 | /** |
||
47 | * @param string $contentConnectorId |
||
48 | * |
||
49 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
50 | * |
||
51 | * @return \Acquia\LiftClient\Entity\Content |
||
52 | */ |
||
53 | View Code Duplication | public function setContentConnectorId($contentConnectorId = 'content_hub') |
|
62 | |||
63 | /** |
||
64 | * Gets the 'content_connector_id' parameter. |
||
65 | * |
||
66 | * @return string |
||
67 | */ |
||
68 | public function getContentConnectorId() |
||
72 | |||
73 | /** |
||
74 | * @param string $baseUrl |
||
75 | * |
||
76 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
77 | * |
||
78 | * @return \Acquia\LiftClient\Entity\Content |
||
79 | */ |
||
80 | public function setBaseUrl($baseUrl) |
||
89 | |||
90 | /** |
||
91 | * Gets the 'base_url' parameter. |
||
92 | * |
||
93 | * @return string |
||
94 | */ |
||
95 | public function getBaseUrl() |
||
99 | |||
100 | /** |
||
101 | * @param ViewMode $viewMode |
||
102 | * |
||
103 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
104 | * |
||
105 | * @return \Acquia\LiftClient\Entity\Content |
||
106 | */ |
||
107 | public function setViewMode(ViewMode $viewMode) |
||
113 | |||
114 | /** |
||
115 | * Gets the 'id' parameter. |
||
116 | * |
||
117 | * @return viewMode |
||
118 | */ |
||
119 | public function getViewMode() |
||
125 | |||
126 | /** |
||
127 | * Gets the 'error' parameter. |
||
128 | * |
||
129 | * @return string |
||
130 | */ |
||
131 | public function getError() |
||
135 | } |
||
136 |
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.