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