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 | * |
||
| 44 | * @var array |
||
| 45 | */ |
||
| 46 | private $dataPointFills = array(); |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Data Label Number Format |
||
| 50 | * |
||
| 51 | * @var string |
||
| 52 | */ |
||
| 53 | private $DlblNumFormat = ''; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Fill |
||
| 57 | * |
||
| 58 | * @var \PhpOffice\PhpPresentation\Style\Fill |
||
| 59 | */ |
||
| 60 | private $fill; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Font |
||
| 64 | * |
||
| 65 | * @var \PhpOffice\PhpPresentation\Style\Font |
||
| 66 | */ |
||
| 67 | private $font; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Label position |
||
| 71 | * |
||
| 72 | * @var string |
||
| 73 | */ |
||
| 74 | private $labelPosition = 'ctr'; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var Marker |
||
| 78 | */ |
||
| 79 | protected $marker; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var Outline |
||
| 83 | */ |
||
| 84 | protected $outline; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * ShowCategoryName |
||
| 88 | * |
||
| 89 | * @var boolean |
||
| 90 | */ |
||
| 91 | private $showCategoryName = false; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * ShowLeaderLines |
||
| 95 | * |
||
| 96 | * @var boolean |
||
| 97 | */ |
||
| 98 | private $showLeaderLines = true; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Show Legend Key |
||
| 102 | * |
||
| 103 | * @var boolean |
||
| 104 | */ |
||
| 105 | private $showLegendKey = false; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * ShowPercentage |
||
| 109 | * |
||
| 110 | * @var boolean |
||
| 111 | */ |
||
| 112 | private $showPercentage = false; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * ShowSeriesName |
||
| 116 | * |
||
| 117 | * @var boolean |
||
| 118 | */ |
||
| 119 | private $showSeriesName = false; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * ShowValue |
||
| 123 | * |
||
| 124 | * @var boolean |
||
| 125 | */ |
||
| 126 | private $showValue = true; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Title |
||
| 130 | * |
||
| 131 | * @var string |
||
| 132 | */ |
||
| 133 | private $title = 'Series Title'; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Values (key/value) |
||
| 137 | * |
||
| 138 | * @var array |
||
| 139 | */ |
||
| 140 | private $values = array(); |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Hash index |
||
| 144 | * |
||
| 145 | * @var string |
||
| 146 | */ |
||
| 147 | private $hashIndex; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Create a new \PhpOffice\PhpPresentation\Shape\Chart\Series instance |
||
| 151 | * |
||
| 152 | * @param string $title Title |
||
| 153 | * @param array $values Values |
||
| 154 | */ |
||
| 155 | 87 | public function __construct($title = 'Series Title', $values = array()) |
|
| 165 | |||
| 166 | /** |
||
| 167 | * Get Title |
||
| 168 | * |
||
| 169 | * @return string |
||
| 170 | */ |
||
| 171 | 47 | public function getTitle() |
|
| 175 | |||
| 176 | /** |
||
| 177 | * Set Title |
||
| 178 | * |
||
| 179 | * @param string $value |
||
| 180 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 181 | */ |
||
| 182 | 1 | public function setTitle($value = 'Series Title') |
|
| 188 | |||
| 189 | /** |
||
| 190 | * Get Data Label NumFormat |
||
| 191 | * |
||
| 192 | * @return string |
||
| 193 | */ |
||
| 194 | 1 | public function getDlblNumFormat() |
|
| 198 | |||
| 199 | /** |
||
| 200 | * Has Data Label NumFormat |
||
| 201 | * |
||
| 202 | * @return string |
||
| 203 | */ |
||
| 204 | 4 | public function hasDlblNumFormat() |
|
| 208 | |||
| 209 | /** |
||
| 210 | * Set Data Label NumFormat |
||
| 211 | * |
||
| 212 | * @param string $value |
||
| 213 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 214 | */ |
||
| 215 | 1 | public function setDlblNumFormat($value = '') |
|
| 220 | |||
| 221 | /** |
||
| 222 | * Get Fill |
||
| 223 | * |
||
| 224 | * @return \PhpOffice\PhpPresentation\Style\Fill |
||
| 225 | */ |
||
| 226 | 43 | public function getFill() |
|
| 230 | |||
| 231 | /** |
||
| 232 | * Set Fill |
||
| 233 | * |
||
| 234 | * @param \PhpOffice\PhpPresentation\Style\Fill $fill |
||
| 235 | * @return Series |
||
| 236 | */ |
||
| 237 | 1 | public function setFill(Fill $fill = null) |
|
| 242 | |||
| 243 | /** |
||
| 244 | * Get DataPointFill |
||
| 245 | * |
||
| 246 | * @param int $dataPointIndex Data point index. |
||
| 247 | * @return \PhpOffice\PhpPresentation\Style\Fill |
||
| 248 | */ |
||
| 249 | 11 | public function getDataPointFill($dataPointIndex) |
|
| 257 | |||
| 258 | /** |
||
| 259 | * Get DataPointFills |
||
| 260 | * |
||
| 261 | * @return Fill[] |
||
| 262 | */ |
||
| 263 | 33 | public function getDataPointFills() |
|
| 267 | |||
| 268 | /** |
||
| 269 | * Get Values |
||
| 270 | * |
||
| 271 | * @return array |
||
| 272 | */ |
||
| 273 | 48 | public function getValues() |
|
| 277 | |||
| 278 | /** |
||
| 279 | * Set Values |
||
| 280 | * |
||
| 281 | * @param array $value |
||
| 282 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 283 | */ |
||
| 284 | 1 | public function setValues($value = array()) |
|
| 290 | |||
| 291 | /** |
||
| 292 | * Add Value |
||
| 293 | * |
||
| 294 | * @param mixed $key |
||
| 295 | * @param mixed $value |
||
| 296 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 297 | */ |
||
| 298 | 1 | public function addValue($key, $value) |
|
| 304 | |||
| 305 | /** |
||
| 306 | * Get ShowSeriesName |
||
| 307 | * |
||
| 308 | * @return boolean |
||
| 309 | */ |
||
| 310 | 25 | public function hasShowSeriesName() |
|
| 314 | |||
| 315 | /** |
||
| 316 | * Set ShowSeriesName |
||
| 317 | * |
||
| 318 | * @param boolean $value |
||
| 319 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 320 | */ |
||
| 321 | 11 | public function setShowSeriesName($value) |
|
| 327 | |||
| 328 | /** |
||
| 329 | * Get ShowCategoryName |
||
| 330 | * |
||
| 331 | * @return boolean |
||
| 332 | */ |
||
| 333 | 46 | public function hasShowCategoryName() |
|
| 337 | |||
| 338 | /** |
||
| 339 | * Set ShowCategoryName |
||
| 340 | * |
||
| 341 | * @param boolean $value |
||
| 342 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 343 | */ |
||
| 344 | 2 | public function setShowCategoryName($value) |
|
| 350 | |||
| 351 | /** |
||
| 352 | * Get ShowValue |
||
| 353 | * |
||
| 354 | * @return boolean |
||
| 355 | */ |
||
| 356 | 8 | public function hasShowLegendKey() |
|
| 360 | |||
| 361 | /** |
||
| 362 | * Set ShowValue |
||
| 363 | * |
||
| 364 | * @param boolean $value |
||
| 365 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 366 | */ |
||
| 367 | 3 | public function setShowLegendKey($value) |
|
| 373 | |||
| 374 | /** |
||
| 375 | * Get ShowValue |
||
| 376 | * |
||
| 377 | * @return boolean |
||
| 378 | */ |
||
| 379 | 46 | public function hasShowValue() |
|
| 383 | |||
| 384 | /** |
||
| 385 | * Set ShowValue |
||
| 386 | * |
||
| 387 | * @param boolean $value |
||
| 388 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 389 | */ |
||
| 390 | 2 | public function setShowValue($value) |
|
| 396 | |||
| 397 | /** |
||
| 398 | * Get ShowPercentage |
||
| 399 | * |
||
| 400 | * @return boolean |
||
| 401 | */ |
||
| 402 | 46 | public function hasShowPercentage() |
|
| 406 | |||
| 407 | /** |
||
| 408 | * Set ShowPercentage |
||
| 409 | * |
||
| 410 | * @param boolean $value |
||
| 411 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 412 | */ |
||
| 413 | 2 | public function setShowPercentage($value) |
|
| 419 | |||
| 420 | /** |
||
| 421 | * Get ShowLeaderLines |
||
| 422 | * |
||
| 423 | * @return boolean |
||
| 424 | */ |
||
| 425 | 24 | public function hasShowLeaderLines() |
|
| 429 | |||
| 430 | /** |
||
| 431 | * Set ShowLeaderLines |
||
| 432 | * |
||
| 433 | * @param boolean $value |
||
| 434 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 435 | */ |
||
| 436 | 1 | public function setShowLeaderLines($value) |
|
| 442 | |||
| 443 | /** |
||
| 444 | * Get font |
||
| 445 | * |
||
| 446 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
| 447 | */ |
||
| 448 | 47 | public function getFont() |
|
| 452 | |||
| 453 | /** |
||
| 454 | * Set font |
||
| 455 | * |
||
| 456 | * @param \PhpOffice\PhpPresentation\Style\Font $pFont Font |
||
| 457 | * @throws \Exception |
||
| 458 | * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph |
||
| 459 | */ |
||
| 460 | 1 | public function setFont(Font $pFont = null) |
|
| 466 | |||
| 467 | /** |
||
| 468 | * Get label position |
||
| 469 | * |
||
| 470 | * @return string |
||
| 471 | */ |
||
| 472 | 8 | public function getLabelPosition() |
|
| 476 | |||
| 477 | /** |
||
| 478 | * Set label position |
||
| 479 | * |
||
| 480 | * @param string $value |
||
| 481 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 482 | */ |
||
| 483 | 1 | public function setLabelPosition($value) |
|
| 489 | |||
| 490 | /** |
||
| 491 | * @return Marker |
||
| 492 | */ |
||
| 493 | 23 | public function getMarker() |
|
| 497 | |||
| 498 | /** |
||
| 499 | * @param Marker $marker |
||
| 500 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 501 | */ |
||
| 502 | 1 | public function setMarker(Marker $marker) |
|
| 507 | |||
| 508 | /** |
||
| 509 | * @return Outline |
||
| 510 | */ |
||
| 511 | 24 | public function getOutline() |
|
| 515 | |||
| 516 | /** |
||
| 517 | * @param Outline $outline |
||
| 518 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 519 | */ |
||
| 520 | 6 | public function setOutline(Outline $outline) |
|
| 525 | |||
| 526 | /** |
||
| 527 | * Get hash code |
||
| 528 | * |
||
| 529 | * @return string Hash code |
||
| 530 | */ |
||
| 531 | 53 | public function getHashCode() |
|
| 535 | |||
| 536 | /** |
||
| 537 | * Get hash index |
||
| 538 | * |
||
| 539 | * Note that this index may vary during script execution! Only reliable moment is |
||
| 540 | * while doing a write of a workbook and when changes are not allowed. |
||
| 541 | * |
||
| 542 | * @return string Hash index |
||
| 543 | */ |
||
| 544 | 2 | public function getHashIndex() |
|
| 548 | |||
| 549 | /** |
||
| 550 | * Set hash index |
||
| 551 | * |
||
| 552 | * Note that this index may vary during script execution! Only reliable moment is |
||
| 553 | * while doing a write of a workbook and when changes are not allowed. |
||
| 554 | * |
||
| 555 | * @param string $value Hash index |
||
| 556 | * @return \PhpOffice\PhpPresentation\Shape\Chart\Series |
||
| 557 | */ |
||
| 558 | 1 | public function setHashIndex($value) |
|
| 563 | |||
| 564 | /** |
||
| 565 | * @return mixed |
||
| 566 | * @link http://php.net/manual/en/language.oop5.cloning.php |
||
| 567 | */ |
||
| 568 | 2 | public function __clone() |
|
| 576 | } |
||
| 577 |