Complex classes like AbstractShape 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 AbstractShape, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | abstract class AbstractShape implements ComparableInterface |
||
| 29 | { |
||
| 30 | /** |
||
| 31 | * Container |
||
| 32 | * |
||
| 33 | * @var \PhpOffice\PhpPresentation\ShapeContainerInterface |
||
| 34 | */ |
||
| 35 | protected $container; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Offset X |
||
| 39 | * |
||
| 40 | * @var int |
||
| 41 | */ |
||
| 42 | protected $offsetX; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Offset Y |
||
| 46 | * |
||
| 47 | * @var int |
||
| 48 | */ |
||
| 49 | protected $offsetY; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Width |
||
| 53 | * |
||
| 54 | * @var int |
||
| 55 | */ |
||
| 56 | protected $width; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Height |
||
| 60 | * |
||
| 61 | * @var int |
||
| 62 | */ |
||
| 63 | protected $height; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Fill |
||
| 67 | * |
||
| 68 | * @var \PhpOffice\PhpPresentation\Style\Fill |
||
| 69 | */ |
||
| 70 | private $fill; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Border |
||
| 74 | * |
||
| 75 | * @var \PhpOffice\PhpPresentation\Style\Border |
||
| 76 | */ |
||
| 77 | private $border; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Rotation |
||
| 81 | * |
||
| 82 | * @var int |
||
| 83 | */ |
||
| 84 | protected $rotation; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Shadow |
||
| 88 | * |
||
| 89 | * @var \PhpOffice\PhpPresentation\Style\Shadow |
||
| 90 | */ |
||
| 91 | protected $shadow; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Hyperlink |
||
| 95 | * |
||
| 96 | * @var \PhpOffice\PhpPresentation\Shape\Hyperlink |
||
| 97 | */ |
||
| 98 | protected $hyperlink; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * PlaceHolder |
||
| 102 | * @var \PhpOffice\PhpPresentation\Shape\Placeholder |
||
| 103 | */ |
||
| 104 | protected $placeholder; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Hash index |
||
| 108 | * |
||
| 109 | * @var string |
||
| 110 | */ |
||
| 111 | private $hashIndex; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Create a new self |
||
| 115 | */ |
||
| 116 | 238 | public function __construct() |
|
| 131 | |||
| 132 | /** |
||
| 133 | * Magic Method : clone |
||
| 134 | */ |
||
| 135 | 1 | public function __clone() |
|
| 142 | |||
| 143 | /** |
||
| 144 | * Get Container, Slide or Group |
||
| 145 | * |
||
| 146 | * @return \PhpOffice\PhpPresentation\ShapeContainerInterface |
||
| 147 | */ |
||
| 148 | 2 | public function getContainer() |
|
| 152 | |||
| 153 | /** |
||
| 154 | * Set Container, Slide or Group |
||
| 155 | * |
||
| 156 | * @param \PhpOffice\PhpPresentation\ShapeContainerInterface $pValue |
||
| 157 | * @param bool $pOverrideOld If a Slide has already been assigned, overwrite it and remove image from old Slide? |
||
| 158 | * @throws \Exception |
||
| 159 | * @return $this |
||
| 160 | */ |
||
| 161 | 173 | public function setContainer(ShapeContainerInterface $pValue = null, $pOverrideOld = false) |
|
| 192 | |||
| 193 | /** |
||
| 194 | * Get OffsetX |
||
| 195 | * |
||
| 196 | * @return int |
||
| 197 | */ |
||
| 198 | 154 | public function getOffsetX() |
|
| 202 | |||
| 203 | /** |
||
| 204 | * Set OffsetX |
||
| 205 | * |
||
| 206 | * @param int $pValue |
||
| 207 | * @return $this |
||
| 208 | */ |
||
| 209 | 68 | public function setOffsetX($pValue = 0) |
|
| 215 | |||
| 216 | /** |
||
| 217 | * Get OffsetY |
||
| 218 | * |
||
| 219 | * @return int |
||
| 220 | */ |
||
| 221 | 154 | public function getOffsetY() |
|
| 225 | |||
| 226 | /** |
||
| 227 | * Set OffsetY |
||
| 228 | * |
||
| 229 | * @param int $pValue |
||
| 230 | * @return $this |
||
| 231 | */ |
||
| 232 | 68 | public function setOffsetY($pValue = 0) |
|
| 238 | |||
| 239 | /** |
||
| 240 | * Get Width |
||
| 241 | * |
||
| 242 | * @return int |
||
| 243 | */ |
||
| 244 | 148 | public function getWidth() |
|
| 248 | |||
| 249 | /** |
||
| 250 | * Set Width |
||
| 251 | * |
||
| 252 | * @param int $pValue |
||
| 253 | * @return $this |
||
| 254 | */ |
||
| 255 | 32 | public function setWidth($pValue = 0) |
|
| 260 | |||
| 261 | /** |
||
| 262 | * Get Height |
||
| 263 | * |
||
| 264 | * @return int |
||
| 265 | */ |
||
| 266 | 148 | public function getHeight() |
|
| 270 | |||
| 271 | /** |
||
| 272 | * Set Height |
||
| 273 | * |
||
| 274 | * @param int $pValue |
||
| 275 | * @return $this |
||
| 276 | */ |
||
| 277 | 32 | public function setHeight($pValue = 0) |
|
| 282 | |||
| 283 | /** |
||
| 284 | * Set width and height with proportional resize |
||
| 285 | * |
||
| 286 | * @param int $width |
||
| 287 | * @param int $height |
||
| 288 | * @example $objDrawing->setWidthAndHeight(160,120); |
||
| 289 | * @return $this |
||
| 290 | */ |
||
| 291 | 1 | public function setWidthAndHeight($width = 0, $height = 0) |
|
| 297 | |||
| 298 | /** |
||
| 299 | * Get Rotation |
||
| 300 | * |
||
| 301 | * @return int |
||
| 302 | */ |
||
| 303 | 69 | public function getRotation() |
|
| 307 | |||
| 308 | /** |
||
| 309 | * Set Rotation |
||
| 310 | * |
||
| 311 | * @param int $pValue |
||
| 312 | * @return $this |
||
| 313 | */ |
||
| 314 | 5 | public function setRotation($pValue = 0) |
|
| 319 | |||
| 320 | /** |
||
| 321 | * Get Fill |
||
| 322 | * |
||
| 323 | * @return \PhpOffice\PhpPresentation\Style\Fill |
||
| 324 | */ |
||
| 325 | 122 | public function getFill() |
|
| 329 | |||
| 330 | /** |
||
| 331 | * Set Fill |
||
| 332 | * @param \PhpOffice\PhpPresentation\Style\Fill $pValue |
||
| 333 | * @return \PhpOffice\PhpPresentation\AbstractShape |
||
| 334 | */ |
||
| 335 | 6 | public function setFill(Fill $pValue = null) |
|
| 340 | |||
| 341 | /** |
||
| 342 | * Get Border |
||
| 343 | * |
||
| 344 | * @return \PhpOffice\PhpPresentation\Style\Border |
||
| 345 | */ |
||
| 346 | 92 | public function getBorder() |
|
| 350 | |||
| 351 | /** |
||
| 352 | * Get Shadow |
||
| 353 | * |
||
| 354 | * @return \PhpOffice\PhpPresentation\Style\Shadow |
||
| 355 | */ |
||
| 356 | 102 | public function getShadow() |
|
| 360 | |||
| 361 | /** |
||
| 362 | * Set Shadow |
||
| 363 | * |
||
| 364 | * @param \PhpOffice\PhpPresentation\Style\Shadow $pValue |
||
| 365 | * @throws \Exception |
||
| 366 | * @return $this |
||
| 367 | */ |
||
| 368 | 3 | public function setShadow(Shadow $pValue = null) |
|
| 373 | |||
| 374 | /** |
||
| 375 | * Has Hyperlink? |
||
| 376 | * |
||
| 377 | * @return boolean |
||
| 378 | */ |
||
| 379 | 96 | public function hasHyperlink() |
|
| 383 | |||
| 384 | /** |
||
| 385 | * Get Hyperlink |
||
| 386 | * |
||
| 387 | * @return \PhpOffice\PhpPresentation\Shape\Hyperlink |
||
| 388 | * @throws \Exception |
||
| 389 | */ |
||
| 390 | 6 | public function getHyperlink() |
|
| 397 | |||
| 398 | /** |
||
| 399 | * Set Hyperlink |
||
| 400 | * |
||
| 401 | * @param \PhpOffice\PhpPresentation\Shape\Hyperlink $pHyperlink |
||
| 402 | * @throws \Exception |
||
| 403 | * @return $this |
||
| 404 | */ |
||
| 405 | 1 | public function setHyperlink(Hyperlink $pHyperlink = null) |
|
| 410 | |||
| 411 | /** |
||
| 412 | * Get hash code |
||
| 413 | * |
||
| 414 | * @return string Hash code |
||
| 415 | */ |
||
| 416 | 84 | public function getHashCode() |
|
| 420 | |||
| 421 | /** |
||
| 422 | * Get hash index |
||
| 423 | * |
||
| 424 | * Note that this index may vary during script execution! Only reliable moment is |
||
| 425 | * while doing a write of a workbook and when changes are not allowed. |
||
| 426 | * |
||
| 427 | * @return string Hash index |
||
| 428 | */ |
||
| 429 | 80 | public function getHashIndex() |
|
| 433 | |||
| 434 | /** |
||
| 435 | * Set hash index |
||
| 436 | * |
||
| 437 | * Note that this index may vary during script execution! Only reliable moment is |
||
| 438 | * while doing a write of a workbook and when changes are not allowed. |
||
| 439 | * |
||
| 440 | * @param string $value Hash index |
||
| 441 | */ |
||
| 442 | 80 | public function setHashIndex($value) |
|
| 446 | |||
| 447 | 70 | public function isPlaceholder() |
|
| 451 | |||
| 452 | 1 | public function getPlaceholder() |
|
| 459 | |||
| 460 | /** |
||
| 461 | * @param \PhpOffice\PhpPresentation\Shape\Placeholder $placeholder |
||
| 462 | * @return $this |
||
| 463 | */ |
||
| 464 | 5 | public function setPlaceHolder(Placeholder $placeholder) |
|
| 469 | } |
||
| 470 |