Complex classes like PhpPresentation 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 PhpPresentation, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | class PhpPresentation |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * Document properties |
||
| 31 | * |
||
| 32 | * @var \PhpOffice\PhpPresentation\DocumentProperties |
||
| 33 | */ |
||
| 34 | protected $documentProperties; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Presentation properties |
||
| 38 | * |
||
| 39 | * @var \PhpOffice\PhpPresentation\PresentationProperties |
||
| 40 | */ |
||
| 41 | protected $presentationProps; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Document layout |
||
| 45 | * |
||
| 46 | * @var \PhpOffice\PhpPresentation\DocumentLayout |
||
| 47 | */ |
||
| 48 | protected $layout; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Collection of Slide objects |
||
| 52 | * |
||
| 53 | * @var \PhpOffice\PhpPresentation\Slide[] |
||
| 54 | */ |
||
| 55 | protected $slideCollection = array(); |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Active slide index |
||
| 59 | * |
||
| 60 | * @var int |
||
| 61 | */ |
||
| 62 | protected $activeSlideIndex = 0; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Collection of Master Slides |
||
| 66 | * @var \ArrayObject|\PhpOffice\PhpPresentation\Slide\SlideMaster[] |
||
| 67 | */ |
||
| 68 | protected $slideMasters; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Create a new PhpPresentation with one Slide |
||
| 72 | */ |
||
| 73 | 222 | public function __construct() |
|
| 87 | |||
| 88 | /** |
||
| 89 | * Get properties |
||
| 90 | * |
||
| 91 | * @return \PhpOffice\PhpPresentation\DocumentProperties |
||
| 92 | * @deprecated for getDocumentProperties |
||
| 93 | */ |
||
| 94 | 1 | public function getProperties() |
|
| 95 | { |
||
| 96 | 1 | return $this->getDocumentProperties(); |
|
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Set properties |
||
| 101 | * |
||
| 102 | * @param \PhpOffice\PhpPresentation\DocumentProperties $value |
||
| 103 | * @deprecated for setDocumentProperties |
||
| 104 | * @return PhpPresentation |
||
| 105 | */ |
||
| 106 | 1 | public function setProperties(DocumentProperties $value) |
|
| 107 | { |
||
| 108 | 1 | return $this->setDocumentProperties($value); |
|
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Get properties |
||
| 113 | * |
||
| 114 | * @return \PhpOffice\PhpPresentation\DocumentProperties |
||
| 115 | */ |
||
| 116 | 186 | public function getDocumentProperties() |
|
| 120 | |||
| 121 | /** |
||
| 122 | * Set properties |
||
| 123 | * |
||
| 124 | * @param \PhpOffice\PhpPresentation\DocumentProperties $value |
||
| 125 | * @return PhpPresentation |
||
| 126 | */ |
||
| 127 | 222 | public function setDocumentProperties(DocumentProperties $value) |
|
| 133 | |||
| 134 | /** |
||
| 135 | * Get presentation properties |
||
| 136 | * |
||
| 137 | * @return \PhpOffice\PhpPresentation\PresentationProperties |
||
| 138 | */ |
||
| 139 | 183 | public function getPresentationProperties() |
|
| 143 | |||
| 144 | /** |
||
| 145 | * Set presentation properties |
||
| 146 | * |
||
| 147 | * @param \PhpOffice\PhpPresentation\PresentationProperties $value |
||
| 148 | * @return PhpPresentation |
||
| 149 | */ |
||
| 150 | 222 | public function setPresentationProperties(PresentationProperties $value) |
|
| 155 | |||
| 156 | /** |
||
| 157 | * Get layout |
||
| 158 | * |
||
| 159 | * @return \PhpOffice\PhpPresentation\DocumentLayout |
||
| 160 | */ |
||
| 161 | 179 | public function getLayout() |
|
| 165 | |||
| 166 | /** |
||
| 167 | * Set layout |
||
| 168 | * |
||
| 169 | * @param \PhpOffice\PhpPresentation\DocumentLayout $value |
||
| 170 | * @return PhpPresentation |
||
| 171 | */ |
||
| 172 | 222 | public function setLayout(DocumentLayout $value) |
|
| 178 | |||
| 179 | /** |
||
| 180 | * Get active slide |
||
| 181 | * |
||
| 182 | * @return \PhpOffice\PhpPresentation\Slide |
||
| 183 | */ |
||
| 184 | 222 | public function getActiveSlide() |
|
| 188 | |||
| 189 | /** |
||
| 190 | * Create slide and add it to this presentation |
||
| 191 | * |
||
| 192 | * @return \PhpOffice\PhpPresentation\Slide |
||
| 193 | * @throws \Exception |
||
| 194 | */ |
||
| 195 | 222 | public function createSlide($prepend=false) |
|
| 205 | |||
| 206 | /** |
||
| 207 | * Add slide |
||
| 208 | * |
||
| 209 | * @param \PhpOffice\PhpPresentation\Slide $slide |
||
| 210 | * @throws \Exception |
||
| 211 | * @return \PhpOffice\PhpPresentation\Slide |
||
| 212 | */ |
||
| 213 | public function prependSlide(Slide $slide = null) |
||
| 218 | |||
| 219 | /** |
||
| 220 | * Add slide |
||
| 221 | * |
||
| 222 | * @param \PhpOffice\PhpPresentation\Slide $slide |
||
| 223 | * @throws \Exception |
||
| 224 | * @return \PhpOffice\PhpPresentation\Slide |
||
| 225 | */ |
||
| 226 | 222 | public function addSlide(Slide $slide = null) |
|
| 232 | |||
| 233 | /** |
||
| 234 | * Remove slide by index |
||
| 235 | * |
||
| 236 | * @param int $index Slide index |
||
| 237 | * @throws \Exception |
||
| 238 | * @return PhpPresentation |
||
| 239 | */ |
||
| 240 | 16 | public function removeSlideByIndex($index = 0) |
|
| 249 | |||
| 250 | /** |
||
| 251 | * Get slide by index |
||
| 252 | * |
||
| 253 | * @param int $index Slide index |
||
| 254 | * @return \PhpOffice\PhpPresentation\Slide |
||
| 255 | * @throws \Exception |
||
| 256 | */ |
||
| 257 | 193 | public function getSlide($index = 0) |
|
| 264 | |||
| 265 | /** |
||
| 266 | * Get all slides |
||
| 267 | * |
||
| 268 | * @return \PhpOffice\PhpPresentation\Slide[] |
||
| 269 | */ |
||
| 270 | 184 | public function getAllSlides() |
|
| 274 | |||
| 275 | /** |
||
| 276 | * Get index for slide |
||
| 277 | * |
||
| 278 | * @param \PhpOffice\PhpPresentation\Slide\AbstractSlide $slide |
||
| 279 | * @return int |
||
| 280 | * @throws \Exception |
||
| 281 | */ |
||
| 282 | 115 | public function getIndex(Slide\AbstractSlide $slide) |
|
| 293 | |||
| 294 | /** |
||
| 295 | * Get slide count |
||
| 296 | * |
||
| 297 | * @return int |
||
| 298 | */ |
||
| 299 | 196 | public function getSlideCount() |
|
| 303 | |||
| 304 | /** |
||
| 305 | * Get active slide index |
||
| 306 | * |
||
| 307 | * @return int Active slide index |
||
| 308 | */ |
||
| 309 | 1 | public function getActiveSlideIndex() |
|
| 313 | |||
| 314 | /** |
||
| 315 | * Set active slide index |
||
| 316 | * |
||
| 317 | * @param int $index Active slide index |
||
| 318 | * @throws \Exception |
||
| 319 | * @return \PhpOffice\PhpPresentation\Slide |
||
| 320 | */ |
||
| 321 | 222 | public function setActiveSlideIndex($index = 0) |
|
| 330 | |||
| 331 | /** |
||
| 332 | * Add external slide |
||
| 333 | * |
||
| 334 | * @param \PhpOffice\PhpPresentation\Slide $slide External slide to add |
||
| 335 | * @throws \Exception |
||
| 336 | * @return \PhpOffice\PhpPresentation\Slide |
||
| 337 | */ |
||
| 338 | 1 | public function addExternalSlide(Slide $slide) |
|
| 346 | |||
| 347 | /** |
||
| 348 | * Get slide iterator |
||
| 349 | * |
||
| 350 | * @return \PhpOffice\PhpPresentation\Slide\Iterator |
||
| 351 | */ |
||
| 352 | 1 | public function getSlideIterator() |
|
| 356 | |||
| 357 | /** |
||
| 358 | * Create a masterslide and add it to this presentation |
||
| 359 | * |
||
| 360 | * @return \PhpOffice\PhpPresentation\Slide\SlideMaster |
||
| 361 | * @throws \Exception |
||
| 362 | */ |
||
| 363 | 222 | public function createMasterSlide() |
|
| 369 | |||
| 370 | /** |
||
| 371 | * Add masterslide |
||
| 372 | * |
||
| 373 | * @param \PhpOffice\PhpPresentation\Slide\SlideMaster $slide |
||
| 374 | * @return \PhpOffice\PhpPresentation\Slide\SlideMaster |
||
| 375 | * @throws \Exception |
||
| 376 | */ |
||
| 377 | 222 | public function addMasterSlide(SlideMaster $slide = null) |
|
| 383 | |||
| 384 | /** |
||
| 385 | * Copy presentation (!= clone!) |
||
| 386 | * |
||
| 387 | * @return PhpPresentation |
||
| 388 | * @throws \Exception |
||
| 389 | */ |
||
| 390 | 1 | public function copy() |
|
| 402 | |||
| 403 | /** |
||
| 404 | * Mark a document as final |
||
| 405 | * @param bool $state |
||
| 406 | * @return PresentationProperties |
||
| 407 | * @deprecated for getPresentationProperties()->markAsFinal() |
||
| 408 | */ |
||
| 409 | 1 | public function markAsFinal($state = true) |
|
| 413 | |||
| 414 | /** |
||
| 415 | * Return if this document is marked as final |
||
| 416 | * @return bool |
||
| 417 | * @deprecated for getPresentationProperties()->isMarkedAsFinal() |
||
| 418 | */ |
||
| 419 | 1 | public function isMarkedAsFinal() |
|
| 423 | |||
| 424 | /** |
||
| 425 | * Set the zoom of the document (in percentage) |
||
| 426 | * @param float $zoom |
||
| 427 | * @return PresentationProperties |
||
| 428 | * @deprecated for getPresentationProperties()->setZoom() |
||
| 429 | */ |
||
| 430 | 1 | public function setZoom($zoom = 1.0) |
|
| 434 | |||
| 435 | /** |
||
| 436 | * Return the zoom (in percentage) |
||
| 437 | * @return float |
||
| 438 | * @deprecated for getPresentationProperties()->getZoom() |
||
| 439 | */ |
||
| 440 | 1 | public function getZoom() |
|
| 444 | |||
| 445 | /** |
||
| 446 | * @return \ArrayObject|Slide\SlideMaster[] |
||
| 447 | */ |
||
| 448 | 222 | public function getAllMasterSlides() |
|
| 452 | |||
| 453 | /** |
||
| 454 | * @param \ArrayObject|Slide\SlideMaster[] $slideMasters |
||
| 455 | * @return $this |
||
| 456 | */ |
||
| 457 | 4 | public function setAllMasterSlides($slideMasters = array()) |
|
| 464 | } |
||
| 465 |