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 | * Hash index |
||
| 137 | * @var string |
||
| 138 | */ |
||
| 139 | private $hashIndex; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Create a new \PhpOffice\PhpPresentation\Shape\Chart\Series instance |
||
| 143 | * |
||
| 144 | * @param string $title Title |
||
| 145 | * @param array $values Values |
||
| 146 | */ |
||
| 147 | 98 | public function __construct($title = 'Series Title', $values = array()) |
|
| 157 | |||
| 158 | /** |
||
| 159 | * Get Title |
||
| 160 | * |
||
| 161 | * @return string |
||
| 162 | */ |
||
| 163 | 54 | public function getTitle() |
|
| 167 | |||
| 168 | /** |
||
| 169 | * Set Title |
||
| 170 | * |
||
| 171 | * @param string $value |
||
| 172 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 173 | */ |
||
| 174 | 1 | public function setTitle($value = 'Series Title') |
|
| 180 | |||
| 181 | /** |
||
| 182 | * Get Data Label NumFormat |
||
| 183 | * |
||
| 184 | * @return string |
||
| 185 | */ |
||
| 186 | 1 | public function getDlblNumFormat() |
|
| 190 | |||
| 191 | /** |
||
| 192 | * Has Data Label NumFormat |
||
| 193 | * |
||
| 194 | * @return string |
||
| 195 | */ |
||
| 196 | 6 | public function hasDlblNumFormat() |
|
| 200 | |||
| 201 | /** |
||
| 202 | * Set Data Label NumFormat |
||
| 203 | * |
||
| 204 | * @param string $value |
||
| 205 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 206 | */ |
||
| 207 | 1 | public function setDlblNumFormat($value = '') |
|
| 212 | |||
| 213 | /** |
||
| 214 | * Get Fill |
||
| 215 | * |
||
| 216 | * @return \PhpOffice\PhpPresentation\Style\Fill |
||
| 217 | */ |
||
| 218 | 49 | public function getFill() |
|
| 222 | |||
| 223 | /** |
||
| 224 | * Set Fill |
||
| 225 | * |
||
| 226 | * @param \PhpOffice\PhpPresentation\Style\Fill $fill |
||
| 227 | * @return Series |
||
| 228 | */ |
||
| 229 | 1 | public function setFill(Fill $fill = null) |
|
| 234 | |||
| 235 | /** |
||
| 236 | * Get DataPointFill |
||
| 237 | * |
||
| 238 | * @param int $dataPointIndex Data point index. |
||
| 239 | * @return \PhpOffice\PhpPresentation\Style\Fill |
||
| 240 | */ |
||
| 241 | 13 | public function getDataPointFill($dataPointIndex) |
|
| 249 | |||
| 250 | /** |
||
| 251 | * Get DataPointFills |
||
| 252 | * |
||
| 253 | * @return Fill[] |
||
| 254 | */ |
||
| 255 | 36 | public function getDataPointFills() |
|
| 259 | |||
| 260 | /** |
||
| 261 | * Get Values |
||
| 262 | * |
||
| 263 | * @return array |
||
| 264 | */ |
||
| 265 | 55 | public function getValues() |
|
| 269 | |||
| 270 | /** |
||
| 271 | * Set Values |
||
| 272 | * |
||
| 273 | * @param array $value |
||
| 274 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 275 | */ |
||
| 276 | 1 | public function setValues($value = array()) |
|
| 282 | |||
| 283 | /** |
||
| 284 | * Add Value |
||
| 285 | * |
||
| 286 | * @param mixed $key |
||
| 287 | * @param mixed $value |
||
| 288 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 289 | */ |
||
| 290 | 1 | public function addValue($key, $value) |
|
| 296 | |||
| 297 | /** |
||
| 298 | * Get ShowSeriesName |
||
| 299 | * |
||
| 300 | * @return boolean |
||
| 301 | */ |
||
| 302 | 31 | public function hasShowSeriesName() |
|
| 306 | |||
| 307 | /** |
||
| 308 | * Set ShowSeriesName |
||
| 309 | * |
||
| 310 | * @param boolean $value |
||
| 311 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 312 | */ |
||
| 313 | 11 | public function setShowSeriesName($value) |
|
| 319 | |||
| 320 | /** |
||
| 321 | * Get ShowCategoryName |
||
| 322 | * |
||
| 323 | * @return boolean |
||
| 324 | */ |
||
| 325 | 53 | public function hasShowCategoryName() |
|
| 329 | |||
| 330 | /** |
||
| 331 | * Set ShowCategoryName |
||
| 332 | * |
||
| 333 | * @param boolean $value |
||
| 334 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 335 | */ |
||
| 336 | 2 | public function setShowCategoryName($value) |
|
| 342 | |||
| 343 | /** |
||
| 344 | * Get ShowValue |
||
| 345 | * |
||
| 346 | * @return boolean |
||
| 347 | */ |
||
| 348 | 10 | public function hasShowLegendKey() |
|
| 352 | |||
| 353 | /** |
||
| 354 | * Set ShowValue |
||
| 355 | * |
||
| 356 | * @param boolean $value |
||
| 357 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 358 | */ |
||
| 359 | 3 | public function setShowLegendKey($value) |
|
| 365 | |||
| 366 | /** |
||
| 367 | * Get ShowValue |
||
| 368 | * |
||
| 369 | * @return boolean |
||
| 370 | */ |
||
| 371 | 53 | public function hasShowValue() |
|
| 375 | |||
| 376 | /** |
||
| 377 | * Set ShowValue |
||
| 378 | * |
||
| 379 | * @param boolean $value |
||
| 380 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 381 | */ |
||
| 382 | 2 | public function setShowValue($value) |
|
| 388 | |||
| 389 | /** |
||
| 390 | * Get ShowPercentage |
||
| 391 | * |
||
| 392 | * @return boolean |
||
| 393 | */ |
||
| 394 | 54 | public function hasShowPercentage() |
|
| 398 | |||
| 399 | /** |
||
| 400 | * Set ShowPercentage |
||
| 401 | * |
||
| 402 | * @param boolean $value |
||
| 403 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 404 | */ |
||
| 405 | 2 | public function setShowPercentage($value) |
|
| 411 | |||
| 412 | /** |
||
| 413 | * Get ShowLeaderLines |
||
| 414 | * |
||
| 415 | * @return boolean |
||
| 416 | */ |
||
| 417 | 4 | public function hasShowSeparator() |
|
| 421 | |||
| 422 | /** |
||
| 423 | * Set Separator |
||
| 424 | * @param string $pValue |
||
| 425 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 426 | */ |
||
| 427 | 4 | public function setSeparator($pValue) |
|
| 432 | |||
| 433 | /** |
||
| 434 | * Get Separator |
||
| 435 | * @return string |
||
| 436 | */ |
||
| 437 | 30 | public function getSeparator() |
|
| 441 | |||
| 442 | /** |
||
| 443 | * Get ShowLeaderLines |
||
| 444 | * |
||
| 445 | * @return boolean |
||
| 446 | */ |
||
| 447 | 30 | public function hasShowLeaderLines() |
|
| 451 | |||
| 452 | /** |
||
| 453 | * Set ShowLeaderLines |
||
| 454 | * |
||
| 455 | * @param boolean $value |
||
| 456 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 457 | */ |
||
| 458 | 1 | public function setShowLeaderLines($value) |
|
| 464 | |||
| 465 | /** |
||
| 466 | * Get font |
||
| 467 | * |
||
| 468 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
| 469 | */ |
||
| 470 | 54 | public function getFont() |
|
| 474 | |||
| 475 | /** |
||
| 476 | * Set font |
||
| 477 | * |
||
| 478 | * @param \PhpOffice\PhpPresentation\Style\Font $pFont Font |
||
| 479 | * @throws \Exception |
||
| 480 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 481 | */ |
||
| 482 | 1 | public function setFont(Font $pFont = null) |
|
| 488 | |||
| 489 | /** |
||
| 490 | * Get label position |
||
| 491 | * |
||
| 492 | * @return string |
||
| 493 | */ |
||
| 494 | 9 | public function getLabelPosition() |
|
| 498 | |||
| 499 | /** |
||
| 500 | * Set label position |
||
| 501 | * |
||
| 502 | * @param string $value |
||
| 503 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 504 | */ |
||
| 505 | 1 | public function setLabelPosition($value) |
|
| 511 | |||
| 512 | /** |
||
| 513 | * @return Marker |
||
| 514 | */ |
||
| 515 | 27 | public function getMarker() |
|
| 519 | |||
| 520 | /** |
||
| 521 | * @param Marker $marker |
||
| 522 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 523 | */ |
||
| 524 | 1 | public function setMarker(Marker $marker) |
|
| 529 | |||
| 530 | /** |
||
| 531 | * @return Outline |
||
| 532 | */ |
||
| 533 | 28 | public function getOutline() |
|
| 537 | |||
| 538 | /** |
||
| 539 | * @param Outline $outline |
||
| 540 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 541 | */ |
||
| 542 | 6 | public function setOutline(Outline $outline) |
|
| 547 | |||
| 548 | /** |
||
| 549 | * Get hash code |
||
| 550 | * |
||
| 551 | * @return string Hash code |
||
| 552 | */ |
||
| 553 | 61 | public function getHashCode() |
|
| 557 | |||
| 558 | /** |
||
| 559 | * Get hash index |
||
| 560 | * |
||
| 561 | * Note that this index may vary during script execution! Only reliable moment is |
||
| 562 | * while doing a write of a workbook and when changes are not allowed. |
||
| 563 | * |
||
| 564 | * @return string Hash index |
||
| 565 | */ |
||
| 566 | 2 | public function getHashIndex() |
|
| 570 | |||
| 571 | /** |
||
| 572 | * Set 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 | * @param string $value Hash index |
||
| 578 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 579 | */ |
||
| 580 | 1 | public function setHashIndex($value) |
|
| 585 | |||
| 586 | |||
| 587 | /** |
||
| 588 | * @link http://php.net/manual/en/language.oop5.cloning.php |
||
| 589 | */ |
||
| 590 | 2 | public function __clone() |
|
| 598 | } |
||
| 599 |