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 Probability extends Entity |
||
8 | { |
||
9 | /** |
||
10 | * @param array $array |
||
11 | */ |
||
12 | public function __construct(array $array = []) |
||
16 | |||
17 | /** |
||
18 | * Sets the 'id' parameter. |
||
19 | * |
||
20 | * @param string $contentId |
||
21 | * |
||
22 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
23 | * |
||
24 | * @return \Acquia\LiftClient\Entity\Probability |
||
25 | */ |
||
26 | public function setContentId($contentId) |
||
35 | |||
36 | /** |
||
37 | * Gets the 'id' parameter. |
||
38 | * |
||
39 | * @return string The Identifier of the Content Identifier |
||
40 | */ |
||
41 | public function getContentId() |
||
45 | |||
46 | /** |
||
47 | * @param string $contentConnectorId |
||
48 | * |
||
49 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
50 | * |
||
51 | * @return \Acquia\LiftClient\Entity\Probability |
||
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 | * Sets the 'content_view_id' parameter. |
||
75 | * |
||
76 | * @param string $contentViewId |
||
77 | * |
||
78 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
79 | * |
||
80 | * @return \Acquia\LiftClient\Entity\Probability |
||
81 | */ |
||
82 | public function setContentViewId($contentViewId) |
||
91 | |||
92 | /** |
||
93 | * Gets the 'content_view_id' parameter. |
||
94 | * |
||
95 | * @return string The Content View Mode Identifier |
||
96 | */ |
||
97 | public function getContentViewId() |
||
101 | |||
102 | /** |
||
103 | * Sets the 'fraction' parameter. |
||
104 | * |
||
105 | * @param int|float $fraction |
||
106 | * |
||
107 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
108 | * |
||
109 | * @return \Acquia\LiftClient\Entity\Probability |
||
110 | */ |
||
111 | public function setFraction($fraction) |
||
123 | |||
124 | /** |
||
125 | * Gets the 'fraction' parameter. |
||
126 | * |
||
127 | * @return int|float The fraction |
||
128 | */ |
||
129 | public function getFraction() |
||
133 | } |
||
134 |
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.