Complex classes like Series 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 Series, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | class Series implements ComparableInterface |
||
| 30 | { |
||
| 31 | /* Label positions */ |
||
| 32 | const LABEL_BESTFIT = 'bestFit'; |
||
| 33 | const LABEL_BOTTOM = 'b'; |
||
| 34 | const LABEL_CENTER = 'ctr'; |
||
| 35 | const LABEL_INSIDEBASE = 'inBase'; |
||
| 36 | const LABEL_INSIDEEND = 'inEnd'; |
||
| 37 | const LABEL_LEFT = 'i'; |
||
| 38 | const LABEL_OUTSIDEEND = 'outEnd'; |
||
| 39 | const LABEL_RIGHT = 'r'; |
||
| 40 | const LABEL_TOP = 't'; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * DataPointFills (key/value) |
||
| 44 | * @var array |
||
| 45 | */ |
||
| 46 | protected $dataPointFills = array(); |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Data Label Number Format |
||
| 50 | * @var string |
||
| 51 | */ |
||
| 52 | protected $DlblNumFormat = ''; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Separator |
||
| 56 | * @var string |
||
| 57 | */ |
||
| 58 | protected $separator = null; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Fill |
||
| 62 | * @var \PhpOffice\PhpPresentation\Style\Fill |
||
| 63 | */ |
||
| 64 | protected $fill; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Font |
||
| 68 | * @var \PhpOffice\PhpPresentation\Style\Font |
||
| 69 | */ |
||
| 70 | protected $font; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Label position |
||
| 74 | * @var string |
||
| 75 | */ |
||
| 76 | protected $labelPosition = 'ctr'; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @var Marker |
||
| 80 | */ |
||
| 81 | protected $marker; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @var Outline |
||
| 85 | */ |
||
| 86 | protected $outline; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Show Category Name |
||
| 90 | * @var boolean |
||
| 91 | */ |
||
| 92 | private $showCategoryName = false; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Show Leader Lines |
||
| 96 | * @var boolean |
||
| 97 | */ |
||
| 98 | private $showLeaderLines = true; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Show Legend Key |
||
| 102 | * @var boolean |
||
| 103 | */ |
||
| 104 | private $showLegendKey = false; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * ShowPercentage |
||
| 108 | * @var boolean |
||
| 109 | */ |
||
| 110 | private $showPercentage = false; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * ShowSeriesName |
||
| 114 | * @var boolean |
||
| 115 | */ |
||
| 116 | private $showSeriesName = false; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * ShowValue |
||
| 120 | * @var boolean |
||
| 121 | */ |
||
| 122 | private $showValue = true; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Title |
||
| 126 | * @var string |
||
| 127 | */ |
||
| 128 | private $title = 'Series Title'; |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Values (key/value) |
||
| 132 | * @var array |
||
| 133 | */ |
||
| 134 | private $values = array(); |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Label color |
||
| 138 | * @var StyleColor |
||
| 139 | */ |
||
| 140 | private $labelColor = null; |
||
| 141 | /** |
||
| 142 | * Hash index |
||
| 143 | * @var string |
||
| 144 | */ |
||
| 145 | private $hashIndex; |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Create a new \PhpOffice\PhpPresentation\Shape\Chart\Series instance |
||
| 149 | * |
||
| 150 | * @param string $title Title |
||
| 151 | * @param array $values Values |
||
| 152 | */ |
||
| 153 | 98 | public function __construct($title = 'Series Title', $values = array()) |
|
| 163 | |||
| 164 | /** |
||
| 165 | * Get Title |
||
| 166 | * |
||
| 167 | * @return string |
||
| 168 | */ |
||
| 169 | 54 | public function getTitle() |
|
| 173 | |||
| 174 | /** |
||
| 175 | * Set Title |
||
| 176 | * |
||
| 177 | * @param string $value |
||
| 178 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 179 | */ |
||
| 180 | 1 | public function setTitle($value = 'Series Title') |
|
| 186 | |||
| 187 | /** |
||
| 188 | * Get Data Label NumFormat |
||
| 189 | * |
||
| 190 | * @return string |
||
| 191 | */ |
||
| 192 | 1 | public function getDlblNumFormat() |
|
| 196 | |||
| 197 | /** |
||
| 198 | * Has Data Label NumFormat |
||
| 199 | * |
||
| 200 | * @return string |
||
| 201 | */ |
||
| 202 | 6 | public function hasDlblNumFormat() |
|
| 206 | |||
| 207 | /** |
||
| 208 | * Set Data Label NumFormat |
||
| 209 | * |
||
| 210 | * @param string $value |
||
| 211 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 212 | */ |
||
| 213 | 1 | public function setDlblNumFormat($value = '') |
|
| 218 | |||
| 219 | /** |
||
| 220 | * Get Fill |
||
| 221 | * |
||
| 222 | * @return \PhpOffice\PhpPresentation\Style\Fill |
||
| 223 | */ |
||
| 224 | 49 | public function getFill() |
|
| 228 | |||
| 229 | /** |
||
| 230 | * Set Fill |
||
| 231 | * |
||
| 232 | * @param \PhpOffice\PhpPresentation\Style\Fill $fill |
||
| 233 | * @return Series |
||
| 234 | */ |
||
| 235 | 1 | public function setFill(Fill $fill = null) |
|
| 240 | |||
| 241 | /** |
||
| 242 | * Get DataPointFill |
||
| 243 | * |
||
| 244 | * @param int $dataPointIndex Data point index. |
||
| 245 | * @return \PhpOffice\PhpPresentation\Style\Fill |
||
| 246 | */ |
||
| 247 | 13 | public function getDataPointFill($dataPointIndex) |
|
| 255 | |||
| 256 | /** |
||
| 257 | * Get DataPointFills |
||
| 258 | * |
||
| 259 | * @return Fill[] |
||
| 260 | */ |
||
| 261 | 36 | public function getDataPointFills() |
|
| 265 | |||
| 266 | /** |
||
| 267 | * Get Values |
||
| 268 | * |
||
| 269 | * @return array |
||
| 270 | */ |
||
| 271 | 55 | public function getValues() |
|
| 275 | |||
| 276 | /** |
||
| 277 | * Set Values |
||
| 278 | * |
||
| 279 | * @param array $value |
||
| 280 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 281 | */ |
||
| 282 | 1 | public function setValues($value = array()) |
|
| 288 | |||
| 289 | /** |
||
| 290 | * Add Value |
||
| 291 | * |
||
| 292 | * @param mixed $key |
||
| 293 | * @param mixed $value |
||
| 294 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 295 | */ |
||
| 296 | 1 | public function addValue($key, $value) |
|
| 302 | |||
| 303 | /** |
||
| 304 | * Get ShowSeriesName |
||
| 305 | * |
||
| 306 | * @return boolean |
||
| 307 | */ |
||
| 308 | 31 | public function hasShowSeriesName() |
|
| 312 | |||
| 313 | /** |
||
| 314 | * Set ShowSeriesName |
||
| 315 | * |
||
| 316 | * @param boolean $value |
||
| 317 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 318 | */ |
||
| 319 | 11 | public function setShowSeriesName($value) |
|
| 325 | |||
| 326 | /** |
||
| 327 | * Get ShowCategoryName |
||
| 328 | * |
||
| 329 | * @return boolean |
||
| 330 | */ |
||
| 331 | 53 | public function hasShowCategoryName() |
|
| 335 | |||
| 336 | /** |
||
| 337 | * Set ShowCategoryName |
||
| 338 | * |
||
| 339 | * @param boolean $value |
||
| 340 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 341 | */ |
||
| 342 | 2 | public function setShowCategoryName($value) |
|
| 348 | |||
| 349 | /** |
||
| 350 | * Get ShowValue |
||
| 351 | * |
||
| 352 | * @return boolean |
||
| 353 | */ |
||
| 354 | 10 | public function hasShowLegendKey() |
|
| 358 | |||
| 359 | /** |
||
| 360 | * Set ShowValue |
||
| 361 | * |
||
| 362 | * @param boolean $value |
||
| 363 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 364 | */ |
||
| 365 | 3 | public function setShowLegendKey($value) |
|
| 371 | |||
| 372 | /** |
||
| 373 | * Get ShowValue |
||
| 374 | * |
||
| 375 | * @return boolean |
||
| 376 | */ |
||
| 377 | 53 | public function hasShowValue() |
|
| 381 | |||
| 382 | /** |
||
| 383 | * Set ShowValue |
||
| 384 | * |
||
| 385 | * @param boolean $value |
||
| 386 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 387 | */ |
||
| 388 | 2 | public function setShowValue($value) |
|
| 394 | |||
| 395 | /** |
||
| 396 | * Get ShowPercentage |
||
| 397 | * |
||
| 398 | * @return boolean |
||
| 399 | */ |
||
| 400 | 54 | public function hasShowPercentage() |
|
| 404 | |||
| 405 | /** |
||
| 406 | * Set ShowPercentage |
||
| 407 | * |
||
| 408 | * @param boolean $value |
||
| 409 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 410 | */ |
||
| 411 | 2 | public function setShowPercentage($value) |
|
| 417 | |||
| 418 | /** |
||
| 419 | * Get ShowLeaderLines |
||
| 420 | * |
||
| 421 | * @return boolean |
||
| 422 | */ |
||
| 423 | 4 | public function hasShowSeparator() |
|
| 427 | |||
| 428 | /** |
||
| 429 | * Set Separator |
||
| 430 | * @param string $pValue |
||
| 431 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 432 | */ |
||
| 433 | 4 | public function setSeparator($pValue) |
|
| 438 | |||
| 439 | /** |
||
| 440 | * Get Separator |
||
| 441 | * @return string |
||
| 442 | */ |
||
| 443 | 30 | public function getSeparator() |
|
| 447 | |||
| 448 | /** |
||
| 449 | * Get ShowLeaderLines |
||
| 450 | * |
||
| 451 | * @return boolean |
||
| 452 | */ |
||
| 453 | 30 | public function hasShowLeaderLines() |
|
| 457 | |||
| 458 | /** |
||
| 459 | * Set ShowLeaderLines |
||
| 460 | * |
||
| 461 | * @param boolean $value |
||
| 462 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 463 | */ |
||
| 464 | 1 | public function setShowLeaderLines($value) |
|
| 470 | |||
| 471 | /** |
||
| 472 | * Get font |
||
| 473 | * |
||
| 474 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
| 475 | */ |
||
| 476 | 54 | public function getFont() |
|
| 480 | |||
| 481 | /** |
||
| 482 | * Set font |
||
| 483 | * |
||
| 484 | * @param \PhpOffice\PhpPresentation\Style\Font $pFont Font |
||
| 485 | * @throws \Exception |
||
| 486 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 487 | */ |
||
| 488 | 1 | public function setFont(Font $pFont = null) |
|
| 494 | |||
| 495 | /** |
||
| 496 | * Get label position |
||
| 497 | * |
||
| 498 | * @return string |
||
| 499 | */ |
||
| 500 | 19 | public function getLabelPosition() |
|
| 504 | |||
| 505 | /** |
||
| 506 | * Set label position |
||
| 507 | * |
||
| 508 | * @param string $value |
||
| 509 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 510 | */ |
||
| 511 | 1 | public function setLabelPosition($value) |
|
| 517 | |||
| 518 | 3 | public function getLabelColor() |
|
| 527 | |||
| 528 | /** |
||
| 529 | * @return Marker |
||
| 530 | */ |
||
| 531 | 27 | public function getMarker() |
|
| 535 | |||
| 536 | /** |
||
| 537 | * @param Marker $marker |
||
| 538 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 539 | */ |
||
| 540 | 1 | public function setMarker(Marker $marker) |
|
| 545 | |||
| 546 | /** |
||
| 547 | * @return Outline |
||
| 548 | */ |
||
| 549 | 28 | public function getOutline() |
|
| 553 | |||
| 554 | /** |
||
| 555 | * @param Outline $outline |
||
| 556 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 557 | */ |
||
| 558 | 6 | public function setOutline(Outline $outline) |
|
| 563 | |||
| 564 | /** |
||
| 565 | * Get hash code |
||
| 566 | * |
||
| 567 | * @return string Hash code |
||
| 568 | */ |
||
| 569 | 61 | public function getHashCode() |
|
| 573 | |||
| 574 | /** |
||
| 575 | * Get hash index |
||
| 576 | * |
||
| 577 | * Note that this index may vary during script execution! Only reliable moment is |
||
| 578 | * while doing a write of a workbook and when changes are not allowed. |
||
| 579 | * |
||
| 580 | * @return string Hash index |
||
| 581 | */ |
||
| 582 | 2 | public function getHashIndex() |
|
| 586 | |||
| 587 | /** |
||
| 588 | * Set hash index |
||
| 589 | * |
||
| 590 | * Note that this index may vary during script execution! Only reliable moment is |
||
| 591 | * while doing a write of a workbook and when changes are not allowed. |
||
| 592 | * |
||
| 593 | * @param string $value Hash index |
||
| 594 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 595 | */ |
||
| 596 | 1 | public function setHashIndex($value) |
|
| 601 | |||
| 602 | |||
| 603 | /** |
||
| 604 | * @link http://php.net/manual/en/language.oop5.cloning.php |
||
| 605 | */ |
||
| 606 | 2 | public function __clone() |
|
| 614 | } |
||
| 615 |