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 |
||
17 | View Code Duplication | trait ColorImageCompressionTrait |
|
|
|||
18 | { |
||
19 | /** |
||
20 | * Available color image downsample type values |
||
21 | * |
||
22 | * @var string[] |
||
23 | */ |
||
24 | protected static $colorImageDownsampleTypeValues = [ |
||
25 | DistillerParametersInterface::IMAGE_DOWNSAMPLE_TYPE_AVERAGE, |
||
26 | DistillerParametersInterface::IMAGE_DOWNSAMPLE_TYPE_BICUBIC, |
||
27 | DistillerParametersInterface::IMAGE_DOWNSAMPLE_TYPE_SUBSAMPLE, |
||
28 | DistillerParametersInterface::IMAGE_DOWNSAMPLE_TYPE_NONE, |
||
29 | ]; |
||
30 | |||
31 | /** |
||
32 | * Available color image filter values |
||
33 | * |
||
34 | * @var string[] |
||
35 | */ |
||
36 | protected static $colorImageFilterValues = [ |
||
37 | DistillerParametersInterface::IMAGE_FILTER_DCT_ENCODE, |
||
38 | DistillerParametersInterface::IMAGE_FILTER_FLATE_ENCODE |
||
39 | ]; |
||
40 | |||
41 | /** |
||
42 | * Get argument value |
||
43 | * |
||
44 | * @param string $name |
||
45 | * |
||
46 | * @return string |
||
47 | */ |
||
48 | abstract protected function getArgumentValue($name); |
||
49 | |||
50 | /** |
||
51 | * Set argument |
||
52 | * |
||
53 | * @param string $argument |
||
54 | * |
||
55 | * @return $this |
||
56 | */ |
||
57 | abstract protected function setArgument($argument); |
||
58 | |||
59 | /** |
||
60 | * Whether to anti alias color images |
||
61 | * |
||
62 | * @return bool |
||
63 | */ |
||
64 | public function isAntiAliasColorImages() |
||
73 | |||
74 | /** |
||
75 | * Set anti alias color images flag |
||
76 | * |
||
77 | * @param bool $antiAliasColorImages |
||
78 | * |
||
79 | * @return $this |
||
80 | */ |
||
81 | public function setAntiAliasColorImages($antiAliasColorImages) |
||
87 | |||
88 | /** |
||
89 | * Whether to auto filter color images |
||
90 | * |
||
91 | * @return bool |
||
92 | */ |
||
93 | public function isAutoFilterColorImages() |
||
102 | |||
103 | /** |
||
104 | * Set auto filter color images flag |
||
105 | * |
||
106 | * @param bool $autoFilterColorImages |
||
107 | * |
||
108 | * @return $this |
||
109 | */ |
||
110 | public function setAutoFilterColorImages($autoFilterColorImages) |
||
116 | |||
117 | /** |
||
118 | * Get color image depth |
||
119 | * |
||
120 | * @return int |
||
121 | */ |
||
122 | public function getColorImageDepth() |
||
131 | |||
132 | /** |
||
133 | * Set color image depth |
||
134 | * |
||
135 | * @param int $colorImageDepth |
||
136 | * |
||
137 | * @return $this |
||
138 | */ |
||
139 | public function setColorImageDepth($colorImageDepth) |
||
145 | |||
146 | /** |
||
147 | * Get color image downsample threshold |
||
148 | * |
||
149 | * @return float |
||
150 | */ |
||
151 | public function getColorImageDownsampleThreshold() |
||
160 | |||
161 | /** |
||
162 | * Set color image downsample threshold |
||
163 | * |
||
164 | * @param float $colorImageDownsampleThreshold |
||
165 | * |
||
166 | * @return $this |
||
167 | */ |
||
168 | public function setColorImageDownsampleThreshold($colorImageDownsampleThreshold) |
||
174 | |||
175 | /** |
||
176 | * Get color image downsample type |
||
177 | * |
||
178 | * @return string |
||
179 | */ |
||
180 | public function getColorImageDownsampleType() |
||
189 | |||
190 | /** |
||
191 | * Set color image downsample type |
||
192 | * |
||
193 | * @param string $colorImageDownsampleType |
||
194 | * |
||
195 | * @throws \InvalidArgumentException |
||
196 | * |
||
197 | * @return $this |
||
198 | */ |
||
199 | public function setColorImageDownsampleType($colorImageDownsampleType) |
||
209 | |||
210 | /** |
||
211 | * Get color image filter |
||
212 | * |
||
213 | * @return string |
||
214 | */ |
||
215 | public function getColorImageFilter() |
||
224 | |||
225 | /** |
||
226 | * Set color image filter |
||
227 | * |
||
228 | * @param string $colorImageFilter |
||
229 | * |
||
230 | * @throws \InvalidArgumentException |
||
231 | * |
||
232 | * @return $this |
||
233 | */ |
||
234 | public function setColorImageFilter($colorImageFilter) |
||
244 | |||
245 | /** |
||
246 | * Get color image resolution |
||
247 | * |
||
248 | * @return int |
||
249 | */ |
||
250 | public function getColorImageResolution() |
||
259 | |||
260 | /** |
||
261 | * Set color image resolution |
||
262 | * |
||
263 | * @param int $colorImageResolution |
||
264 | * |
||
265 | * @return $this |
||
266 | */ |
||
267 | public function setColorImageResolution($colorImageResolution) |
||
273 | |||
274 | /** |
||
275 | * Whether to downsample color images |
||
276 | * |
||
277 | * @return bool |
||
278 | */ |
||
279 | public function isDownsampleColorImages() |
||
288 | |||
289 | /** |
||
290 | * Set downsample color images flag |
||
291 | * |
||
292 | * @param bool $downsampleColorImages |
||
293 | * |
||
294 | * @return $this |
||
295 | */ |
||
296 | public function setDownsampleColorImages($downsampleColorImages) |
||
302 | |||
303 | /** |
||
304 | * Whether to encode color images |
||
305 | * |
||
306 | * @return bool |
||
307 | */ |
||
308 | public function isEncodeColorImages() |
||
317 | |||
318 | /** |
||
319 | * Set encode color images flag |
||
320 | * |
||
321 | * @param bool $encodeColorImages |
||
322 | * |
||
323 | * @return $this |
||
324 | */ |
||
325 | public function setEncodeColorImages($encodeColorImages) |
||
331 | } |
||
332 |
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.