Complex classes like EntityTtfItem 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 EntityTtfItem, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class EntityTtfItem implements EntityInterface |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var int |
||
| 21 | */ |
||
| 22 | protected $anchorPoint; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var int |
||
| 26 | */ |
||
| 27 | protected $xPos; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var int |
||
| 31 | */ |
||
| 32 | protected $yPos; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var int |
||
| 36 | */ |
||
| 37 | protected $width; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var int |
||
| 41 | */ |
||
| 42 | protected $height; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var int |
||
| 46 | */ |
||
| 47 | protected $orion; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var string |
||
| 51 | */ |
||
| 52 | protected $description; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | protected $fontName; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var int |
||
| 61 | */ |
||
| 62 | protected $fontSize; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var int |
||
| 66 | */ |
||
| 67 | protected $fontBold; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var int |
||
| 71 | */ |
||
| 72 | protected $fontItalic; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var int |
||
| 76 | */ |
||
| 77 | protected $fontUnderline; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var int |
||
| 81 | */ |
||
| 82 | protected $inverted; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var int |
||
| 86 | */ |
||
| 87 | protected $alignment; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var string |
||
| 91 | */ |
||
| 92 | protected $data; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var int |
||
| 96 | */ |
||
| 97 | protected $ftbMode; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var int |
||
| 101 | */ |
||
| 102 | protected $lineSpacing; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var int |
||
| 106 | */ |
||
| 107 | protected $removeBlank; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @var int |
||
| 111 | */ |
||
| 112 | protected $fontWidth; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @var int |
||
| 116 | */ |
||
| 117 | protected $charSpacing; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @var int |
||
| 121 | */ |
||
| 122 | protected $phantomField; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @return int |
||
| 126 | */ |
||
| 127 | 2 | public function getAnchorPoint() |
|
| 131 | |||
| 132 | /** |
||
| 133 | * @param int $anchorPoint |
||
| 134 | */ |
||
| 135 | public function setAnchorPoint($anchorPoint) |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @return int |
||
| 142 | */ |
||
| 143 | 2 | public function getXPos() |
|
| 147 | |||
| 148 | /** |
||
| 149 | * @param int $xPos |
||
| 150 | */ |
||
| 151 | public function setXPos($xPos) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @return int |
||
| 158 | */ |
||
| 159 | 2 | public function getYPos() |
|
| 163 | |||
| 164 | /** |
||
| 165 | * @param int $yPos |
||
| 166 | */ |
||
| 167 | public function setYPos($yPos) |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @return int |
||
| 174 | */ |
||
| 175 | 2 | public function getWidth() |
|
| 179 | |||
| 180 | /** |
||
| 181 | * @param int $width |
||
| 182 | */ |
||
| 183 | public function setWidth($width) |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @return int |
||
| 190 | */ |
||
| 191 | 2 | public function getHeight() |
|
| 195 | |||
| 196 | /** |
||
| 197 | * @param int $height |
||
| 198 | */ |
||
| 199 | public function setHeight($height) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @return int |
||
| 206 | */ |
||
| 207 | 2 | public function getOrion() |
|
| 211 | |||
| 212 | /** |
||
| 213 | * @param int $orion |
||
| 214 | */ |
||
| 215 | public function setOrion($orion) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @return string |
||
| 222 | */ |
||
| 223 | 2 | public function getDescription() |
|
| 227 | |||
| 228 | /** |
||
| 229 | * @param string $description |
||
| 230 | */ |
||
| 231 | public function setDescription($description) |
||
| 235 | |||
| 236 | /** |
||
| 237 | * @return string |
||
| 238 | */ |
||
| 239 | 2 | public function getFontName() |
|
| 243 | |||
| 244 | /** |
||
| 245 | * @param string $fontName |
||
| 246 | */ |
||
| 247 | public function setFontName($fontName) |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @return int |
||
| 254 | */ |
||
| 255 | 2 | public function getFontSize() |
|
| 259 | |||
| 260 | /** |
||
| 261 | * @param int $fontSize |
||
| 262 | */ |
||
| 263 | public function setFontSize($fontSize) |
||
| 267 | |||
| 268 | /** |
||
| 269 | * @return int |
||
| 270 | */ |
||
| 271 | 2 | public function getFontBold() |
|
| 275 | |||
| 276 | /** |
||
| 277 | * @param int $fontBold |
||
| 278 | */ |
||
| 279 | public function setFontBold($fontBold) |
||
| 283 | |||
| 284 | /** |
||
| 285 | * @return int |
||
| 286 | */ |
||
| 287 | 2 | public function getFontItalic() |
|
| 291 | |||
| 292 | /** |
||
| 293 | * @param int $fontItalic |
||
| 294 | */ |
||
| 295 | public function setFontItalic($fontItalic) |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @return int |
||
| 302 | */ |
||
| 303 | 2 | public function getFontUnderline() |
|
| 307 | |||
| 308 | /** |
||
| 309 | * @param int $fontUnderline |
||
| 310 | */ |
||
| 311 | public function setFontUnderline($fontUnderline) |
||
| 315 | |||
| 316 | /** |
||
| 317 | * @return int |
||
| 318 | */ |
||
| 319 | 2 | public function getInverted() |
|
| 323 | |||
| 324 | /** |
||
| 325 | * @param int $inverted |
||
| 326 | */ |
||
| 327 | public function setInverted($inverted) |
||
| 331 | |||
| 332 | /** |
||
| 333 | * @return int |
||
| 334 | */ |
||
| 335 | 2 | public function getAlignment() |
|
| 339 | |||
| 340 | /** |
||
| 341 | * @param int $alignment |
||
| 342 | */ |
||
| 343 | public function setAlignment($alignment) |
||
| 347 | |||
| 348 | /** |
||
| 349 | * @return string |
||
| 350 | */ |
||
| 351 | 2 | public function getData() |
|
| 355 | |||
| 356 | /** |
||
| 357 | * @param string $data |
||
| 358 | */ |
||
| 359 | public function setData($data) |
||
| 363 | |||
| 364 | /** |
||
| 365 | * @return int |
||
| 366 | */ |
||
| 367 | 2 | public function getFtbMode() |
|
| 371 | |||
| 372 | /** |
||
| 373 | * @param int $ftbMode |
||
| 374 | */ |
||
| 375 | public function setFtbMode($ftbMode) |
||
| 379 | |||
| 380 | /** |
||
| 381 | * @return int |
||
| 382 | */ |
||
| 383 | 2 | public function getLineSpacing() |
|
| 387 | |||
| 388 | /** |
||
| 389 | * @param int $lineSpacing |
||
| 390 | */ |
||
| 391 | public function setLineSpacing($lineSpacing) |
||
| 395 | |||
| 396 | /** |
||
| 397 | * @return int |
||
| 398 | */ |
||
| 399 | 2 | public function getRemoveBlank() |
|
| 403 | |||
| 404 | /** |
||
| 405 | * @param int $removeBlank |
||
| 406 | */ |
||
| 407 | public function setRemoveBlank($removeBlank) |
||
| 411 | |||
| 412 | /** |
||
| 413 | * @return int |
||
| 414 | */ |
||
| 415 | 2 | public function getFontWidth() |
|
| 419 | |||
| 420 | /** |
||
| 421 | * @param int $fontWidth |
||
| 422 | */ |
||
| 423 | public function setFontWidth($fontWidth) |
||
| 427 | |||
| 428 | /** |
||
| 429 | * @return int |
||
| 430 | */ |
||
| 431 | 2 | public function getCharSpacing() |
|
| 435 | |||
| 436 | /** |
||
| 437 | * @param int $charSpacing |
||
| 438 | */ |
||
| 439 | public function setCharSpacing($charSpacing) |
||
| 443 | |||
| 444 | /** |
||
| 445 | * @return int |
||
| 446 | */ |
||
| 447 | 2 | public function getPhantomField() |
|
| 451 | |||
| 452 | /** |
||
| 453 | * @param int $phantomField |
||
| 454 | */ |
||
| 455 | public function setPhantomField($phantomField) |
||
| 459 | } |
||
| 460 |