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 |
||
| 21 | trait ColorConversionTrait |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * Get argument value |
||
| 25 | * |
||
| 26 | * @param string $name |
||
| 27 | * |
||
| 28 | * @return string |
||
| 29 | */ |
||
| 30 | abstract protected function getArgumentValue($name); |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Set argument |
||
| 34 | * |
||
| 35 | * @param string $argument |
||
| 36 | * |
||
| 37 | * @return $this |
||
| 38 | */ |
||
| 39 | abstract protected function setArgument($argument); |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Get PDF settings |
||
| 43 | * |
||
| 44 | * @return string |
||
| 45 | */ |
||
| 46 | abstract public function getPdfSettings(); |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Get cal CMYK profile |
||
| 50 | * |
||
| 51 | * @return null|string |
||
| 52 | */ |
||
| 53 | public function getCalCmykProfile() |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Set cal CMYK profile |
||
| 65 | * |
||
| 66 | * @param string $valCmykProfile |
||
| 67 | * |
||
| 68 | * @return $this |
||
| 69 | */ |
||
| 70 | public function setCalCmykProfile($valCmykProfile) |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Get cal gray profile |
||
| 79 | * |
||
| 80 | * @return null|string |
||
| 81 | */ |
||
| 82 | public function getCalGrayProfile() |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Set cal gray profile |
||
| 94 | * |
||
| 95 | * @param string $valGrayProfile |
||
| 96 | * |
||
| 97 | * @return $this |
||
| 98 | */ |
||
| 99 | public function setCalGrayProfile($valGrayProfile) |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Get cal RGB profile |
||
| 108 | * |
||
| 109 | * @return null|string |
||
| 110 | */ |
||
| 111 | public function getCalRgbProfile() |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Set cal RGB profile |
||
| 123 | * |
||
| 124 | * @param string $valRgbProfile |
||
| 125 | * |
||
| 126 | * @return $this |
||
| 127 | */ |
||
| 128 | public function setCalRgbProfile($valRgbProfile) |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Get color conversion strategy |
||
| 137 | * |
||
| 138 | * @return string |
||
| 139 | */ |
||
| 140 | public function getColorConversionStrategy() |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Set color conversion strategy |
||
| 160 | * |
||
| 161 | * @param string $colorConversionStrategy |
||
| 162 | * |
||
| 163 | * @throws \InvalidArgumentException |
||
| 164 | * |
||
| 165 | * @return $this |
||
| 166 | */ |
||
| 167 | public function setColorConversionStrategy($colorConversionStrategy) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Whether to convert CMYK images to RGB |
||
| 181 | * |
||
| 182 | * @return bool |
||
| 183 | */ |
||
| 184 | public function isConvertCmykImagesToRgb() |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Set convert convert CMYK images to RGB flag |
||
| 196 | * |
||
| 197 | * @param bool $convertCmykImagesToRgb |
||
| 198 | * |
||
| 199 | * @return $this |
||
| 200 | */ |
||
| 201 | public function setConvertCmykImagesToRgb($convertCmykImagesToRgb) |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Whether to convert images to indexed |
||
| 210 | * |
||
| 211 | * @return bool |
||
| 212 | */ |
||
| 213 | public function isConvertImagesToIndexed() |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Set convert images to indexed flag |
||
| 225 | * |
||
| 226 | * @param bool $convertImagesToIndexed |
||
| 227 | * |
||
| 228 | * @return $this |
||
| 229 | */ |
||
| 230 | public function setConvertImagesToIndexed($convertImagesToIndexed) |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Get default rendering intent |
||
| 239 | * |
||
| 240 | * @return string |
||
| 241 | */ |
||
| 242 | public function getDefaultRenderingIntent() |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Set default rendering intent |
||
| 254 | * |
||
| 255 | * @param string $defaultRenderingIntent |
||
| 256 | * |
||
| 257 | * @throws \InvalidArgumentException |
||
| 258 | * |
||
| 259 | * @return $this |
||
| 260 | */ |
||
| 261 | public function setDefaultRenderingIntent($defaultRenderingIntent) |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Whether to preserve halftone info |
||
| 275 | * |
||
| 276 | * @return bool |
||
| 277 | */ |
||
| 278 | public function isPreserveHalftoneInfo() |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Set preserve halftone info flag |
||
| 290 | * |
||
| 291 | * @param bool $preserveHalftoneInfo |
||
| 292 | * |
||
| 293 | * @return $this |
||
| 294 | */ |
||
| 295 | public function setPreserveHalftoneInfo($preserveHalftoneInfo) |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Whether to preserve overprint settings |
||
| 304 | * |
||
| 305 | * @return bool |
||
| 306 | */ |
||
| 307 | public function isPreserveOverprintSettings() |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Set preserve overprint settings flag |
||
| 325 | * |
||
| 326 | * @param bool $preserveOverprintSettings |
||
| 327 | * |
||
| 328 | * @return $this |
||
| 329 | */ |
||
| 330 | public function setPreserveOverprintSettings($preserveOverprintSettings) |
||
| 336 | |||
| 337 | /** |
||
| 338 | * Get sRGB profile |
||
| 339 | * |
||
| 340 | * @return null|string |
||
| 341 | */ |
||
| 342 | public function getSRgbProfile() |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Set sRGB profile |
||
| 354 | * |
||
| 355 | * @param string $sRgbProfile |
||
| 356 | * |
||
| 357 | * @return $this |
||
| 358 | */ |
||
| 359 | public function setSRgbProfile($sRgbProfile) |
||
| 365 | |||
| 366 | /** |
||
| 367 | * Get transfer function info |
||
| 368 | * |
||
| 369 | * @return string |
||
| 370 | */ |
||
| 371 | public function getTransferFunctionInfo() |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Set transfer function info |
||
| 383 | * |
||
| 384 | * @param string $transferFunctionInfo |
||
| 385 | * |
||
| 386 | * @throws \InvalidArgumentException |
||
| 387 | * |
||
| 388 | * @return $this |
||
| 389 | */ |
||
| 390 | public function setTransferFunctionInfo($transferFunctionInfo) |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Get UCR and BG info |
||
| 404 | * |
||
| 405 | * @return string |
||
| 406 | */ |
||
| 407 | public function getUcrAndBgInfo() |
||
| 422 | |||
| 423 | /** |
||
| 424 | * Set UCR and BG info |
||
| 425 | * |
||
| 426 | * @param string $ucrAndBgInfo |
||
| 427 | * |
||
| 428 | * @throws \InvalidArgumentException |
||
| 429 | * |
||
| 430 | * @return $this |
||
| 431 | */ |
||
| 432 | public function setUcrAndBgInfo($ucrAndBgInfo) |
||
| 443 | } |
||
| 444 |