Complex classes like EntityReadDesign 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 EntityReadDesign, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class EntityReadDesign implements EntityInterface |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $name; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var int |
||
| 26 | */ |
||
| 27 | protected $height; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var int |
||
| 31 | */ |
||
| 32 | protected $width; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var int |
||
| 36 | */ |
||
| 37 | protected $storageMode; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var int |
||
| 41 | */ |
||
| 42 | protected $saveDesign; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var int |
||
| 46 | */ |
||
| 47 | protected $printDesign; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var int |
||
| 51 | */ |
||
| 52 | protected $driverId; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var int |
||
| 56 | */ |
||
| 57 | protected $printCount; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var int |
||
| 61 | */ |
||
| 62 | protected $cycleSize; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var int |
||
| 66 | */ |
||
| 67 | protected $readOk; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var EntityLineItem[] |
||
| 71 | */ |
||
| 72 | protected $lineArray = []; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var EntityBoxItem[] |
||
| 76 | */ |
||
| 77 | protected $boxArray = []; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var EntityTtfItem[] |
||
| 81 | */ |
||
| 82 | protected $ttfArray = []; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var EntityBarcodeItem[] |
||
| 86 | */ |
||
| 87 | protected $barcodeArray = []; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var EntityPictureItem[] |
||
| 91 | */ |
||
| 92 | protected $pictureArray = []; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var EntityVarPrompt[] |
||
| 96 | */ |
||
| 97 | protected $promptArray = []; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var EntityVarSeq[] |
||
| 101 | */ |
||
| 102 | protected $seqArray = []; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var EntityVarRtc[] |
||
| 106 | */ |
||
| 107 | protected $rtcArray = []; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @var EntityVarDatabase[] |
||
| 111 | */ |
||
| 112 | protected $databaseArray = []; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @var EntityVarUserId[] |
||
| 116 | */ |
||
| 117 | protected $userIdArray = []; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @var EntityVarShiftCode[] |
||
| 121 | */ |
||
| 122 | protected $shiftCodeArray = []; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @var EntityVarMachineId[] |
||
| 126 | */ |
||
| 127 | protected $machineIdArray = []; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @var EntityVarDatabaseField[] |
||
| 131 | */ |
||
| 132 | protected $databaseFieldArray = []; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @var EntityVarMacro[] |
||
| 136 | */ |
||
| 137 | protected $macroArray = []; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @var EntityVarMacroOutput[] |
||
| 141 | */ |
||
| 142 | protected $macroOutputArray = []; |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @var EntityVarSerial[] |
||
| 146 | */ |
||
| 147 | protected $serialVarArray = []; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @var EntitySettingsById[] |
||
| 151 | */ |
||
| 152 | protected $settingsArray = []; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @return string |
||
| 156 | */ |
||
| 157 | 1 | public function getName() |
|
| 161 | |||
| 162 | /** |
||
| 163 | * @param string $name |
||
| 164 | */ |
||
| 165 | public function setName($name) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @return int |
||
| 172 | */ |
||
| 173 | 1 | public function getHeight() |
|
| 177 | |||
| 178 | /** |
||
| 179 | * @param int $height |
||
| 180 | */ |
||
| 181 | public function setHeight($height) |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @return int |
||
| 188 | */ |
||
| 189 | 1 | public function getWidth() |
|
| 193 | |||
| 194 | /** |
||
| 195 | * @param int $width |
||
| 196 | */ |
||
| 197 | public function setWidth($width) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @return int |
||
| 204 | */ |
||
| 205 | 1 | public function getStorageMode() |
|
| 209 | |||
| 210 | /** |
||
| 211 | * @param int $storageMode |
||
| 212 | */ |
||
| 213 | public function setStorageMode($storageMode) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @return int |
||
| 220 | */ |
||
| 221 | 1 | public function getSaveDesign() |
|
| 225 | |||
| 226 | /** |
||
| 227 | * @param int $saveDesign |
||
| 228 | */ |
||
| 229 | public function setSaveDesign($saveDesign) |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @return int |
||
| 236 | */ |
||
| 237 | 1 | public function getPrintDesign() |
|
| 241 | |||
| 242 | /** |
||
| 243 | * @param int $printDesign |
||
| 244 | */ |
||
| 245 | public function setPrintDesign($printDesign) |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @return int |
||
| 252 | */ |
||
| 253 | 1 | public function getDriverId() |
|
| 257 | |||
| 258 | /** |
||
| 259 | * @param int $driverId |
||
| 260 | */ |
||
| 261 | public function setDriverId($driverId) |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @return int |
||
| 268 | */ |
||
| 269 | 1 | public function getPrintCount() |
|
| 273 | |||
| 274 | /** |
||
| 275 | * @param int $printCount |
||
| 276 | */ |
||
| 277 | public function setPrintCount($printCount) |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @return int |
||
| 284 | */ |
||
| 285 | 1 | public function getCycleSize() |
|
| 289 | |||
| 290 | /** |
||
| 291 | * @param int $cycleSize |
||
| 292 | */ |
||
| 293 | public function setCycleSize($cycleSize) |
||
| 297 | |||
| 298 | /** |
||
| 299 | * @return int |
||
| 300 | */ |
||
| 301 | 1 | public function getReadOk() |
|
| 305 | |||
| 306 | /** |
||
| 307 | * @param int $readOk |
||
| 308 | */ |
||
| 309 | public function setReadOk($readOk) |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @return EntityLineItem[] |
||
| 316 | */ |
||
| 317 | 1 | public function getLineArray() |
|
| 321 | |||
| 322 | /** |
||
| 323 | * @param EntityLineItem[] $lineArray |
||
| 324 | */ |
||
| 325 | public function setLineArray(array $lineArray) |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @return EntityBoxItem[] |
||
| 332 | */ |
||
| 333 | 1 | public function getBoxArray() |
|
| 337 | |||
| 338 | /** |
||
| 339 | * @param EntityBoxItem[] $boxArray |
||
| 340 | */ |
||
| 341 | public function setBoxArray(array $boxArray) |
||
| 345 | |||
| 346 | /** |
||
| 347 | * @return EntityTtfItem[] |
||
| 348 | */ |
||
| 349 | 1 | public function getTtfArray() |
|
| 353 | |||
| 354 | /** |
||
| 355 | * @param EntityTtfItem[] $ttfArray |
||
| 356 | */ |
||
| 357 | public function setTtfArray(array $ttfArray) |
||
| 361 | |||
| 362 | /** |
||
| 363 | * @return EntityBarcodeItem[] |
||
| 364 | */ |
||
| 365 | 1 | public function getBarcodeArray() |
|
| 369 | |||
| 370 | /** |
||
| 371 | * @param EntityBarcodeItem[] $barcodeArray |
||
| 372 | */ |
||
| 373 | public function setBarcodeArray(array $barcodeArray) |
||
| 377 | |||
| 378 | /** |
||
| 379 | * @return EntityPictureItem[] |
||
| 380 | */ |
||
| 381 | 1 | public function getPictureArray() |
|
| 385 | |||
| 386 | /** |
||
| 387 | * @param EntityPictureItem[] $pictureArray |
||
| 388 | */ |
||
| 389 | public function setPictureArray(array $pictureArray) |
||
| 393 | |||
| 394 | /** |
||
| 395 | * @return EntityVarPrompt[] |
||
| 396 | */ |
||
| 397 | 1 | public function getPromptArray() |
|
| 401 | |||
| 402 | /** |
||
| 403 | * @param EntityVarPrompt[] $promptArray |
||
| 404 | */ |
||
| 405 | public function setPromptArray(array $promptArray) |
||
| 409 | |||
| 410 | /** |
||
| 411 | * @return EntityVarSeq[] |
||
| 412 | */ |
||
| 413 | 1 | public function getSeqArray() |
|
| 417 | |||
| 418 | /** |
||
| 419 | * @param EntityVarSeq[] $seqArray |
||
| 420 | */ |
||
| 421 | public function setSeqArray(array $seqArray) |
||
| 425 | |||
| 426 | /** |
||
| 427 | * @return EntityVarRtc[] |
||
| 428 | */ |
||
| 429 | 1 | public function getRtcArray() |
|
| 433 | |||
| 434 | /** |
||
| 435 | * @param EntityVarRtc[] $rtcArray |
||
| 436 | */ |
||
| 437 | public function setRtcArray(array $rtcArray) |
||
| 441 | |||
| 442 | /** |
||
| 443 | * @return EntityVarDatabase[] |
||
| 444 | */ |
||
| 445 | 1 | public function getDatabaseArray() |
|
| 449 | |||
| 450 | /** |
||
| 451 | * @param EntityVarDatabase[] $databaseArray |
||
| 452 | */ |
||
| 453 | public function setDatabaseArray(array $databaseArray) |
||
| 457 | |||
| 458 | /** |
||
| 459 | * @return EntityVarUserId[] |
||
| 460 | */ |
||
| 461 | 1 | public function getUserIdArray() |
|
| 465 | |||
| 466 | /** |
||
| 467 | * @param EntityVarUserId[] $userIdArray |
||
| 468 | */ |
||
| 469 | public function setUserIdArray(array $userIdArray) |
||
| 473 | |||
| 474 | /** |
||
| 475 | * @return EntityVarShiftCode[] |
||
| 476 | */ |
||
| 477 | 1 | public function getShiftCodeArray() |
|
| 481 | |||
| 482 | /** |
||
| 483 | * @param EntityVarShiftCode[] $shiftCodeArray |
||
| 484 | */ |
||
| 485 | public function setShiftCodeArray(array $shiftCodeArray) |
||
| 489 | |||
| 490 | /** |
||
| 491 | * @return EntityVarMachineId[] |
||
| 492 | */ |
||
| 493 | 1 | public function getMachineIdArray() |
|
| 497 | |||
| 498 | /** |
||
| 499 | * @param EntityVarMachineId[] $machineIdArray |
||
| 500 | */ |
||
| 501 | public function setMachineIdArray(array $machineIdArray) |
||
| 505 | |||
| 506 | /** |
||
| 507 | * @return EntityVarDatabaseField[] |
||
| 508 | */ |
||
| 509 | 1 | public function getDatabaseFieldArray() |
|
| 513 | |||
| 514 | /** |
||
| 515 | * @param EntityVarDatabaseField[] $databaseFieldArray |
||
| 516 | */ |
||
| 517 | public function setDatabaseFieldArray(array $databaseFieldArray) |
||
| 521 | |||
| 522 | /** |
||
| 523 | * @return EntityVarMacro[] |
||
| 524 | */ |
||
| 525 | 1 | public function getMacroArray() |
|
| 529 | |||
| 530 | /** |
||
| 531 | * @param EntityVarMacro[] $macroArray |
||
| 532 | */ |
||
| 533 | public function setMacroArray(array $macroArray) |
||
| 537 | |||
| 538 | /** |
||
| 539 | * @return EntityVarMacroOutput[] |
||
| 540 | */ |
||
| 541 | 1 | public function getMacroOutputArray() |
|
| 545 | |||
| 546 | /** |
||
| 547 | * @param EntityVarMacroOutput[] $macroOutputArray |
||
| 548 | */ |
||
| 549 | public function setMacroOutputArray(array $macroOutputArray) |
||
| 553 | |||
| 554 | /** |
||
| 555 | * @return EntityVarSerial[] |
||
| 556 | */ |
||
| 557 | 1 | public function getSerialVarArray() |
|
| 561 | |||
| 562 | /** |
||
| 563 | * @param EntityVarSerial[] $serialVarArray |
||
| 564 | */ |
||
| 565 | public function setSerialVarArray(array $serialVarArray) |
||
| 569 | |||
| 570 | /** |
||
| 571 | * @return EntitySettingsById[] |
||
| 572 | */ |
||
| 573 | 1 | public function getSettingsArray() |
|
| 577 | |||
| 578 | /** |
||
| 579 | * @param EntitySettingsById[] $settingsArray |
||
| 580 | */ |
||
| 581 | public function setSettingsArray(array $settingsArray) |
||
| 585 | } |
||
| 586 |