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 ViewMode extends \ArrayObject |
||
8 | { |
||
9 | use EntityTrait; |
||
10 | |||
11 | /** |
||
12 | * @param array $array |
||
13 | */ |
||
14 | public function __construct(array $array = []) |
||
18 | |||
19 | /** |
||
20 | * Sets the 'id' parameter. |
||
21 | * |
||
22 | * @param string $id |
||
23 | * |
||
24 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
25 | * |
||
26 | * @return \Acquia\LiftClient\Entity\ViewMode |
||
27 | */ |
||
28 | View Code Duplication | public function setId($id) |
|
37 | |||
38 | /** |
||
39 | * Gets the 'id' parameter. |
||
40 | * |
||
41 | * @return string |
||
42 | */ |
||
43 | public function getId() |
||
47 | |||
48 | /** |
||
49 | * Gets the 'id' parameter. |
||
50 | * |
||
51 | * @return string |
||
52 | */ |
||
53 | public function getLabel() |
||
57 | |||
58 | /** |
||
59 | * Gets the 'url' parameter. |
||
60 | * |
||
61 | * @return string |
||
62 | */ |
||
63 | public function getUrl() |
||
67 | |||
68 | /** |
||
69 | * Gets the 'html' parameter. |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | public function getHtml() |
||
77 | |||
78 | /** |
||
79 | * Gets the 'preview_image' parameter. |
||
80 | * |
||
81 | * @return string |
||
82 | */ |
||
83 | public function getPreviewImage() |
||
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.