Complex classes like ColorConversionTrait often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ColorConversionTrait, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | trait ColorConversionTrait |
||
18 | { |
||
19 | /** |
||
20 | * Available color conversion strategy values |
||
21 | * |
||
22 | * @var string[] |
||
23 | */ |
||
24 | protected static $colorConversionStrategyValues = [ |
||
25 | DistillerParametersInterface::COLOR_CONVERSION_STRATEGY_LEAVE_COLOR_UNCHANGED, |
||
26 | DistillerParametersInterface::COLOR_CONVERSION_STRATEGY_USE_DEVICE_INDEPENDENT_COLOR, |
||
27 | DistillerParametersInterface::COLOR_CONVERSION_STRATEGY_GRAY, |
||
28 | DistillerParametersInterface::COLOR_CONVERSION_STRATEGY_RGB, |
||
29 | DistillerParametersInterface::COLOR_CONVERSION_STRATEGY_CMYK |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * Available default rendering intent values |
||
34 | * |
||
35 | * @var string[] |
||
36 | */ |
||
37 | protected static $defaultRenderingIntentValues = [ |
||
38 | DistillerParametersInterface::DEFAULT_RENDERING_INTENT_DEFAULT, |
||
39 | DistillerParametersInterface::DEFAULT_RENDERING_INTENT_PERCEPTUAL, |
||
40 | DistillerParametersInterface::DEFAULT_RENDERING_INTENT_SATURATION, |
||
41 | DistillerParametersInterface::DEFAULT_RENDERING_INTENT_RELATIVE_COLORIMETRIC, |
||
42 | DistillerParametersInterface::DEFAULT_RENDERING_INTENT_ABSOLUTE_COLORIMETRIC |
||
43 | ]; |
||
44 | |||
45 | /** |
||
46 | * Available transfer function info values |
||
47 | * |
||
48 | * @var string[] |
||
49 | */ |
||
50 | protected static $transferFunctionInfoValues = [ |
||
51 | DistillerParametersInterface::TRANSFER_FUNCTION_INFO_PRESERVE, |
||
52 | DistillerParametersInterface::TRANSFER_FUNCTION_INFO_REMOVE, |
||
53 | DistillerParametersInterface::TRANSFER_FUNCTION_INFO_APPLY |
||
54 | ]; |
||
55 | |||
56 | /** |
||
57 | * Available UCR and BG info values |
||
58 | * |
||
59 | * @var string[] |
||
60 | */ |
||
61 | protected static $ucrAndBgInfoValues = [ |
||
62 | DistillerParametersInterface::UCR_AND_BG_INFO_PRESERVE, |
||
63 | DistillerParametersInterface::UCR_AND_BG_INFO_REMOVE |
||
64 | ]; |
||
65 | |||
66 | /** |
||
67 | * Get argument value |
||
68 | * |
||
69 | * @param string $name |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | abstract protected function getArgumentValue($name); |
||
74 | |||
75 | /** |
||
76 | * Set argument |
||
77 | * |
||
78 | * @param string $argument |
||
79 | * |
||
80 | * @return $this |
||
81 | */ |
||
82 | abstract protected function setArgument($argument); |
||
83 | |||
84 | /** |
||
85 | * Get cal CMYK profile |
||
86 | * |
||
87 | * @return null|string |
||
88 | */ |
||
89 | public function getCalCmykProfile() |
||
98 | |||
99 | /** |
||
100 | * Set cal CMYK profile |
||
101 | * |
||
102 | * @param string $valCmykProfile |
||
103 | * |
||
104 | * @return $this |
||
105 | */ |
||
106 | public function setCalCmykProfile($valCmykProfile) |
||
112 | |||
113 | /** |
||
114 | * Get cal gray profile |
||
115 | * |
||
116 | * @return null|string |
||
117 | */ |
||
118 | public function getCalGrayProfile() |
||
127 | |||
128 | /** |
||
129 | * Set cal gray profile |
||
130 | * |
||
131 | * @param string $valGrayProfile |
||
132 | * |
||
133 | * @return $this |
||
134 | */ |
||
135 | public function setCalGrayProfile($valGrayProfile) |
||
141 | |||
142 | /** |
||
143 | * Get cal RGB profile |
||
144 | * |
||
145 | * @return null|string |
||
146 | */ |
||
147 | public function getCalRgbProfile() |
||
156 | |||
157 | /** |
||
158 | * Set cal RGB profile |
||
159 | * |
||
160 | * @param string $valRgbProfile |
||
161 | * |
||
162 | * @return $this |
||
163 | */ |
||
164 | public function setCalRgbProfile($valRgbProfile) |
||
170 | |||
171 | /** |
||
172 | * Get color conversion strategy |
||
173 | * |
||
174 | * @return string |
||
175 | */ |
||
176 | public function getColorConversionStrategy() |
||
185 | |||
186 | /** |
||
187 | * Set color conversion strategy |
||
188 | * |
||
189 | * @param string $colorConversionStrategy |
||
190 | * |
||
191 | * @throws \InvalidArgumentException |
||
192 | * |
||
193 | * @return $this |
||
194 | */ |
||
195 | public function setColorConversionStrategy($colorConversionStrategy) |
||
205 | |||
206 | /** |
||
207 | * Whether to convert CMYK images to RGB |
||
208 | * |
||
209 | * @return bool |
||
210 | */ |
||
211 | public function isConvertCmykImagesToRgb() |
||
220 | |||
221 | /** |
||
222 | * Set convert convert CMYK images to RGB flag |
||
223 | * |
||
224 | * @param bool $convertCmykImagesToRgb |
||
225 | * |
||
226 | * @return $this |
||
227 | */ |
||
228 | public function setConvertCmykImagesToRgb($convertCmykImagesToRgb) |
||
234 | |||
235 | /** |
||
236 | * Whether to convert images to indexed |
||
237 | * |
||
238 | * @return bool |
||
239 | */ |
||
240 | public function isConvertImagesToIndexed() |
||
249 | |||
250 | /** |
||
251 | * Set convert images to indexed flag |
||
252 | * |
||
253 | * @param bool $convertImagesToIndexed |
||
254 | * |
||
255 | * @return $this |
||
256 | */ |
||
257 | public function setConvertImagesToIndexed($convertImagesToIndexed) |
||
263 | |||
264 | /** |
||
265 | * Get default rendering intent |
||
266 | * |
||
267 | * @return string |
||
268 | */ |
||
269 | public function getDefaultRenderingIntent() |
||
278 | |||
279 | /** |
||
280 | * Set default rendering intent |
||
281 | * |
||
282 | * @param string $defaultRenderingIntent |
||
283 | * |
||
284 | * @throws \InvalidArgumentException |
||
285 | * |
||
286 | * @return $this |
||
287 | */ |
||
288 | public function setDefaultRenderingIntent($defaultRenderingIntent) |
||
298 | |||
299 | /** |
||
300 | * Get sRGB profile |
||
301 | * |
||
302 | * @return null|string |
||
303 | */ |
||
304 | public function getsRgbProfile() |
||
313 | |||
314 | /** |
||
315 | * Set sRGB profile |
||
316 | * |
||
317 | * @param string $sRgbProfile |
||
318 | * |
||
319 | * @return $this |
||
320 | */ |
||
321 | public function setsRgbProfile($sRgbProfile) |
||
327 | |||
328 | /** |
||
329 | * Whether to preserve halftone info |
||
330 | * |
||
331 | * @return bool |
||
332 | */ |
||
333 | public function isPreserveHalftoneInfo() |
||
342 | |||
343 | /** |
||
344 | * Set preserve halftone info flag |
||
345 | * |
||
346 | * @param bool $preserveHalftoneInfo |
||
347 | * |
||
348 | * @return $this |
||
349 | */ |
||
350 | public function setPreserveHalftoneInfo($preserveHalftoneInfo) |
||
356 | |||
357 | /** |
||
358 | * Whether to preserve overprint settings |
||
359 | * |
||
360 | * @return bool |
||
361 | */ |
||
362 | public function isPreserveOverprintSettings() |
||
371 | |||
372 | /** |
||
373 | * Set preserve overprint settings flag |
||
374 | * |
||
375 | * @param bool $preserveOverprintSettings |
||
376 | * |
||
377 | * @return $this |
||
378 | */ |
||
379 | public function setPreserveOverprintSettings($preserveOverprintSettings) |
||
385 | |||
386 | /** |
||
387 | * Get transfer function info |
||
388 | * |
||
389 | * @return string |
||
390 | */ |
||
391 | public function getTransferFunctionInfo() |
||
400 | |||
401 | /** |
||
402 | * Set transfer function info |
||
403 | * |
||
404 | * @param string $transferFunctionInfo |
||
405 | * |
||
406 | * @throws \InvalidArgumentException |
||
407 | * |
||
408 | * @return $this |
||
409 | */ |
||
410 | public function setTransferFunctionInfo($transferFunctionInfo) |
||
420 | |||
421 | /** |
||
422 | * Get UCR and BG info |
||
423 | * |
||
424 | * @return string |
||
425 | */ |
||
426 | public function getUcrAndBgInfo() |
||
435 | |||
436 | /** |
||
437 | * Set UCR and BG info |
||
438 | * |
||
439 | * @param string $ucrAndBgInfo |
||
440 | * |
||
441 | * @throws \InvalidArgumentException |
||
442 | * |
||
443 | * @return $this |
||
444 | */ |
||
445 | public function setUcrAndBgInfo($ucrAndBgInfo) |
||
455 | } |
||
456 |