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 |
||
21 | View Code Duplication | class CustomFieldResourceModel extends AbstractModel implements ResourceModelInterface |
|
|
|||
22 | { |
||
23 | /** |
||
24 | * Custom Field ID. |
||
25 | * |
||
26 | * Comment: Custom Field ID |
||
27 | * |
||
28 | * @SA\Type("string") |
||
29 | * @SA\SerializedName("id") |
||
30 | * |
||
31 | * @var string|null |
||
32 | */ |
||
33 | protected $id; |
||
34 | |||
35 | /** |
||
36 | * Account ID. |
||
37 | * |
||
38 | * Comment: Account ID |
||
39 | * |
||
40 | * @SA\Type("string") |
||
41 | * @SA\SerializedName("accountId") |
||
42 | * |
||
43 | * @var string|null |
||
44 | */ |
||
45 | protected $accountId; |
||
46 | |||
47 | /** |
||
48 | * Custom field title. |
||
49 | * |
||
50 | * @SA\Type("string") |
||
51 | * @SA\SerializedName("title") |
||
52 | * |
||
53 | * @var string|null |
||
54 | */ |
||
55 | protected $title; |
||
56 | |||
57 | /** |
||
58 | * Custom field type |
||
59 | * Type of custom field, Enum: Text, DropDown, Numeric, Money, Percentage, Date, Duration, Checkbox. |
||
60 | * |
||
61 | * @see \Zibios\WrikePhpLibrary\Enum\CustomFieldTypeEnum |
||
62 | * |
||
63 | * @SA\Type("string") |
||
64 | * @SA\SerializedName("type") |
||
65 | * |
||
66 | * @var string|null |
||
67 | */ |
||
68 | protected $type; |
||
69 | |||
70 | /** |
||
71 | * List of user IDs, who share the custom field. |
||
72 | * |
||
73 | * Comment: Contact ID list |
||
74 | * |
||
75 | * @SA\Type("array<string>") |
||
76 | * @SA\SerializedName("sharedIds") |
||
77 | * |
||
78 | * @var array|string[]|null |
||
79 | */ |
||
80 | protected $sharedIds; |
||
81 | |||
82 | /** |
||
83 | * Deleted flag is present and set to true, if custom field is deleted/hidden. |
||
84 | * |
||
85 | * @SA\Type("boolean") |
||
86 | * @SA\SerializedName("deleted") |
||
87 | * |
||
88 | * @var bool|null |
||
89 | */ |
||
90 | protected $deleted; |
||
91 | |||
92 | /** |
||
93 | * @return string|null |
||
94 | */ |
||
95 | 1 | public function getId() |
|
99 | |||
100 | /** |
||
101 | * @param string|null $id |
||
102 | * |
||
103 | * @return $this |
||
104 | */ |
||
105 | 1 | public function setId($id) |
|
111 | |||
112 | /** |
||
113 | * @return string|null |
||
114 | */ |
||
115 | 1 | public function getAccountId() |
|
119 | |||
120 | /** |
||
121 | * @param string|null $accountId |
||
122 | * |
||
123 | * @return $this |
||
124 | */ |
||
125 | 1 | public function setAccountId($accountId) |
|
131 | |||
132 | /** |
||
133 | * @return string|null |
||
134 | */ |
||
135 | 1 | public function getTitle() |
|
139 | |||
140 | /** |
||
141 | * @param string|null $title |
||
142 | * |
||
143 | * @return $this |
||
144 | */ |
||
145 | 1 | public function setTitle($title) |
|
151 | |||
152 | /** |
||
153 | * @return null|string |
||
154 | */ |
||
155 | 1 | public function getType() |
|
159 | |||
160 | /** |
||
161 | * @param null|string $type |
||
162 | * |
||
163 | * @return $this |
||
164 | */ |
||
165 | 1 | public function setType($type) |
|
171 | |||
172 | /** |
||
173 | * @return array|string[]|null |
||
174 | */ |
||
175 | 1 | public function getSharedIds() |
|
179 | |||
180 | /** |
||
181 | * @param array|string[]|null $sharedIds |
||
182 | * |
||
183 | * @return $this |
||
184 | */ |
||
185 | 1 | public function setSharedIds($sharedIds) |
|
191 | |||
192 | /** |
||
193 | * @return bool|null |
||
194 | */ |
||
195 | 1 | public function getDeleted() |
|
199 | |||
200 | /** |
||
201 | * @param bool|null $deleted |
||
202 | * |
||
203 | * @return $this |
||
204 | */ |
||
205 | 1 | public function setDeleted($deleted) |
|
211 | } |
||
212 |
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.