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 |
||
18 | class IntegerWriter extends Writer |
||
19 | { |
||
20 | /** |
||
21 | * Use byte order aware trait |
||
22 | */ |
||
23 | use ByteOrderAwareTrait; |
||
24 | |||
25 | /** |
||
26 | * Write unsigned 8-bit integer (char) data to the stream |
||
27 | * |
||
28 | * @param int $value The value |
||
29 | * |
||
30 | * @return int |
||
31 | */ |
||
32 | public function writeUnsignedInteger8($value) |
||
36 | |||
37 | /** |
||
38 | * Write signed 8-bit integer (char) data to the stream |
||
39 | * |
||
40 | * @param int $value The value |
||
41 | * |
||
42 | * @return int |
||
43 | */ |
||
44 | public function writeSignedInteger8($value) |
||
48 | |||
49 | /** |
||
50 | * Write unsigned 16-bit integer (short) data to the stream |
||
51 | * |
||
52 | * @param int $value The value |
||
53 | * |
||
54 | * @return int |
||
55 | */ |
||
56 | View Code Duplication | public function writeUnsignedInteger16($value) |
|
71 | |||
72 | /** |
||
73 | * Write signed 16-bit integer (short) data to the stream |
||
74 | * |
||
75 | * @param int $value The value |
||
76 | * |
||
77 | * @return int |
||
78 | */ |
||
79 | View Code Duplication | public function writeSignedInteger16($value) |
|
91 | |||
92 | /** |
||
93 | * Write unsigned 24-bit integer (short) data to the stream |
||
94 | * |
||
95 | * @param int $value The value |
||
96 | * |
||
97 | * @return int |
||
98 | */ |
||
99 | public function writeUnsignedInteger24($value) |
||
114 | |||
115 | /** |
||
116 | * Write signed 24-bit integer (short) data to the stream |
||
117 | * |
||
118 | * @param int $value The value |
||
119 | * |
||
120 | * @return int |
||
121 | */ |
||
122 | public function writeSignedInteger24($value) |
||
130 | |||
131 | /** |
||
132 | * Write unsigned 32-bit integer (long) data to the stream |
||
133 | * |
||
134 | * @param int $value The value |
||
135 | * |
||
136 | * @return int |
||
137 | */ |
||
138 | View Code Duplication | public function writeUnsignedInteger32($value) |
|
153 | |||
154 | /** |
||
155 | * Write signed 32-bit integer (long) data to the stream |
||
156 | * |
||
157 | * @param int $value The value |
||
158 | * |
||
159 | * @return int |
||
160 | */ |
||
161 | View Code Duplication | public function writeSignedInteger32($value) |
|
173 | |||
174 | /** |
||
175 | * Write unsigned 64-bit integer (long long) data to the stream |
||
176 | * |
||
177 | * @param int $value The value |
||
178 | * |
||
179 | * @return int |
||
180 | */ |
||
181 | View Code Duplication | public function writeUnsignedInteger64($value) |
|
196 | |||
197 | /** |
||
198 | * Write signed 64-bit integer (long long) data to the stream |
||
199 | * |
||
200 | * @param int $value The value |
||
201 | * |
||
202 | * @return int |
||
203 | */ |
||
204 | View Code Duplication | public function writeSignedInteger64($value) |
|
216 | } |
||
217 |
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.