Complex classes like HighchartsDataLabels 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 HighchartsDataLabels, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | final class HighchartsDataLabels implements JsonSerializable { |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Align. |
||
| 29 | * |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | private $align = "center"; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Allow overlap. |
||
| 36 | * |
||
| 37 | * @var boolean |
||
| 38 | * @since 4.1.0 |
||
| 39 | */ |
||
| 40 | private $allowOverlap = false; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Background color. |
||
| 44 | * |
||
| 45 | * @var string |
||
| 46 | * @since 2.2.1 |
||
| 47 | */ |
||
| 48 | private $backgroundColor; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Border color. |
||
| 52 | * |
||
| 53 | * @var string |
||
| 54 | * @since 2.2.1 |
||
| 55 | */ |
||
| 56 | private $borderColor; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Border radius. |
||
| 60 | * |
||
| 61 | * @var integer |
||
| 62 | * @since 2.2.1 |
||
| 63 | */ |
||
| 64 | private $borderRadius = 0; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Border width. |
||
| 68 | * |
||
| 69 | * @var integer |
||
| 70 | * @since 2.2.1 |
||
| 71 | */ |
||
| 72 | private $borderWidth = 0; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Class name. |
||
| 76 | * |
||
| 77 | * @var string |
||
| 78 | * @since 5.0.0 |
||
| 79 | */ |
||
| 80 | private $className; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Color. |
||
| 84 | * |
||
| 85 | * @var string |
||
| 86 | */ |
||
| 87 | private $color; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Crop. |
||
| 91 | * |
||
| 92 | * @var boolean |
||
| 93 | * @since 2.3.3 |
||
| 94 | */ |
||
| 95 | private $crop = true; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Defer. |
||
| 99 | * |
||
| 100 | * @var boolean |
||
| 101 | * @since 4.0 |
||
| 102 | */ |
||
| 103 | private $defer = true; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Enabled. |
||
| 107 | * |
||
| 108 | * @var boolean |
||
| 109 | */ |
||
| 110 | private $enabled = false; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Format. |
||
| 114 | * |
||
| 115 | * @var string |
||
| 116 | * @since 3.0 |
||
| 117 | */ |
||
| 118 | private $format = "{y}"; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Formatter. |
||
| 122 | * |
||
| 123 | * @var string |
||
| 124 | */ |
||
| 125 | private $formatter; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Inside. |
||
| 129 | * |
||
| 130 | * @var boolean |
||
| 131 | * @since 3.0 |
||
| 132 | */ |
||
| 133 | private $inside; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Overflow. |
||
| 137 | * |
||
| 138 | * @var string |
||
| 139 | * @since 3.0.6 |
||
| 140 | */ |
||
| 141 | private $overflow = "justify"; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Padding. |
||
| 145 | * |
||
| 146 | * @var integer |
||
| 147 | * @since 2.2.1 |
||
| 148 | */ |
||
| 149 | private $padding = 5; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Rotation. |
||
| 153 | * |
||
| 154 | * @var integer |
||
| 155 | */ |
||
| 156 | private $rotation = 0; |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Shadow. |
||
| 160 | * |
||
| 161 | * @var boolean|array |
||
| 162 | * @since 2.2.1 |
||
| 163 | */ |
||
| 164 | private $shadow = false; |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Shape. |
||
| 168 | * |
||
| 169 | * @var string |
||
| 170 | * @since 4.1.2 |
||
| 171 | */ |
||
| 172 | private $shape = "square"; |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Style. |
||
| 176 | * |
||
| 177 | * @var array |
||
| 178 | * @since 4.1.0 |
||
| 179 | */ |
||
| 180 | private $style = ["color" => "contrast", "fontSize" => "11px", "fontWeight" => "bold", "textOutline" => "1px contrast"]; |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Use HTML. |
||
| 184 | * |
||
| 185 | * @var boolean |
||
| 186 | */ |
||
| 187 | private $useHTML = false; |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Vertical align. |
||
| 191 | * |
||
| 192 | * @var string |
||
| 193 | * @since 2.3.3 |
||
| 194 | */ |
||
| 195 | private $verticalAlign; |
||
| 196 | |||
| 197 | /** |
||
| 198 | * X. |
||
| 199 | * |
||
| 200 | * @var integer |
||
| 201 | */ |
||
| 202 | private $x = 0; |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Y. |
||
| 206 | * |
||
| 207 | * @var integer |
||
| 208 | */ |
||
| 209 | private $y = -6; |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Z index. |
||
| 213 | * |
||
| 214 | * @var integer |
||
| 215 | * @since 2.3.5 |
||
| 216 | */ |
||
| 217 | private $zIndex = 6; |
||
| 218 | |||
| 219 | /** |
||
| 220 | * Constructor. |
||
| 221 | * |
||
| 222 | * @param boolean $ignoreDefaultValues Ignore the default values. |
||
| 223 | */ |
||
| 224 | public function __construct($ignoreDefaultValues = true) { |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Clear. |
||
| 232 | * |
||
| 233 | * @return void |
||
| 234 | */ |
||
| 235 | public function clear() { |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Get the align. |
||
| 315 | * |
||
| 316 | * @return string Returns the align. |
||
| 317 | */ |
||
| 318 | public function getAlign() { |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Get the allow overlap. |
||
| 324 | * |
||
| 325 | * @return boolean Returns the allow overlap. |
||
| 326 | */ |
||
| 327 | public function getAllowOverlap() { |
||
| 330 | |||
| 331 | /** |
||
| 332 | * Get the background color. |
||
| 333 | * |
||
| 334 | * @return string Returns the background color. |
||
| 335 | */ |
||
| 336 | public function getBackgroundColor() { |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Get the border color. |
||
| 342 | * |
||
| 343 | * @return string Returns the border color. |
||
| 344 | */ |
||
| 345 | public function getBorderColor() { |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Get the border radius. |
||
| 351 | * |
||
| 352 | * @return integer Returns the border radius. |
||
| 353 | */ |
||
| 354 | public function getBorderRadius() { |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Get the border width. |
||
| 360 | * |
||
| 361 | * @return integer Returns the border width. |
||
| 362 | */ |
||
| 363 | public function getBorderWidth() { |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Get the class name. |
||
| 369 | * |
||
| 370 | * @return string Returns the class name. |
||
| 371 | */ |
||
| 372 | public function getClassName() { |
||
| 375 | |||
| 376 | /** |
||
| 377 | * Get the color. |
||
| 378 | * |
||
| 379 | * @return string Returns the color. |
||
| 380 | */ |
||
| 381 | public function getColor() { |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Get the crop. |
||
| 387 | * |
||
| 388 | * @return boolean Returns the crop. |
||
| 389 | */ |
||
| 390 | public function getCrop() { |
||
| 393 | |||
| 394 | /** |
||
| 395 | * Get the defer. |
||
| 396 | * |
||
| 397 | * @return boolean Returns the defer. |
||
| 398 | */ |
||
| 399 | public function getDefer() { |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Get the enabled. |
||
| 405 | * |
||
| 406 | * @return boolean Returns the enabled. |
||
| 407 | */ |
||
| 408 | public function getEnabled() { |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Get the format. |
||
| 414 | * |
||
| 415 | * @return string Returns the format. |
||
| 416 | */ |
||
| 417 | public function getFormat() { |
||
| 420 | |||
| 421 | /** |
||
| 422 | * Get the formatter. |
||
| 423 | * |
||
| 424 | * @return string Returns the formatter. |
||
| 425 | */ |
||
| 426 | public function getFormatter() { |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Get the inside. |
||
| 432 | * |
||
| 433 | * @return boolean Returns the inside. |
||
| 434 | */ |
||
| 435 | public function getInside() { |
||
| 438 | |||
| 439 | /** |
||
| 440 | * Get the overflow. |
||
| 441 | * |
||
| 442 | * @return string Returns the overflow. |
||
| 443 | */ |
||
| 444 | public function getOverflow() { |
||
| 447 | |||
| 448 | /** |
||
| 449 | * Get the padding. |
||
| 450 | * |
||
| 451 | * @return integer Returns the padding. |
||
| 452 | */ |
||
| 453 | public function getPadding() { |
||
| 456 | |||
| 457 | /** |
||
| 458 | * Get the rotation. |
||
| 459 | * |
||
| 460 | * @return integer Returns the rotation. |
||
| 461 | */ |
||
| 462 | public function getRotation() { |
||
| 465 | |||
| 466 | /** |
||
| 467 | * Get the shadow. |
||
| 468 | * |
||
| 469 | * @return boolean|array Returns the shadow. |
||
| 470 | */ |
||
| 471 | public function getShadow() { |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Get the shape. |
||
| 477 | * |
||
| 478 | * @return string Returns the shape. |
||
| 479 | */ |
||
| 480 | public function getShape() { |
||
| 483 | |||
| 484 | /** |
||
| 485 | * Get the style. |
||
| 486 | * |
||
| 487 | * @return array Returns the style. |
||
| 488 | */ |
||
| 489 | public function getStyle() { |
||
| 492 | |||
| 493 | /** |
||
| 494 | * Get the use HTML. |
||
| 495 | * |
||
| 496 | * @return boolean Returns the use HTML. |
||
| 497 | */ |
||
| 498 | public function getUseHTML() { |
||
| 501 | |||
| 502 | /** |
||
| 503 | * Get the vertical align. |
||
| 504 | * |
||
| 505 | * @return string Returns the vertical align. |
||
| 506 | */ |
||
| 507 | public function getVerticalAlign() { |
||
| 510 | |||
| 511 | /** |
||
| 512 | * Get the x. |
||
| 513 | * |
||
| 514 | * @return integer Returns the x. |
||
| 515 | */ |
||
| 516 | public function getX() { |
||
| 519 | |||
| 520 | /** |
||
| 521 | * Get the y. |
||
| 522 | * |
||
| 523 | * @return integer Returns the y. |
||
| 524 | */ |
||
| 525 | public function getY() { |
||
| 528 | |||
| 529 | /** |
||
| 530 | * Get the z index. |
||
| 531 | * |
||
| 532 | * @return integer Returns the z index. |
||
| 533 | */ |
||
| 534 | public function getZIndex() { |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Serialize this instance. |
||
| 540 | * |
||
| 541 | * @return array Returns an array representing this instance. |
||
| 542 | */ |
||
| 543 | public function jsonSerialize() { |
||
| 546 | |||
| 547 | /** |
||
| 548 | * Set the align. |
||
| 549 | * |
||
| 550 | * @param string $align The align. |
||
| 551 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 552 | */ |
||
| 553 | public function setAlign($align) { |
||
| 563 | |||
| 564 | /** |
||
| 565 | * Set the allow overlap. |
||
| 566 | * |
||
| 567 | * @param boolean $allowOverlap The allow overlap. |
||
| 568 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 569 | */ |
||
| 570 | public function setAllowOverlap($allowOverlap) { |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Set the background color. |
||
| 577 | * |
||
| 578 | * @param string $backgroundColor The background color. |
||
| 579 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 580 | */ |
||
| 581 | public function setBackgroundColor($backgroundColor) { |
||
| 585 | |||
| 586 | /** |
||
| 587 | * Set the border color. |
||
| 588 | * |
||
| 589 | * @param string $borderColor The border color. |
||
| 590 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 591 | */ |
||
| 592 | public function setBorderColor($borderColor) { |
||
| 596 | |||
| 597 | /** |
||
| 598 | * Set the border radius. |
||
| 599 | * |
||
| 600 | * @param integer $borderRadius The border radius. |
||
| 601 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 602 | */ |
||
| 603 | public function setBorderRadius($borderRadius) { |
||
| 607 | |||
| 608 | /** |
||
| 609 | * Set the border width. |
||
| 610 | * |
||
| 611 | * @param integer $borderWidth The border width. |
||
| 612 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 613 | */ |
||
| 614 | public function setBorderWidth($borderWidth) { |
||
| 618 | |||
| 619 | /** |
||
| 620 | * Set the class name. |
||
| 621 | * |
||
| 622 | * @param string $className The class name. |
||
| 623 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 624 | */ |
||
| 625 | public function setClassName($className) { |
||
| 629 | |||
| 630 | /** |
||
| 631 | * Set the color. |
||
| 632 | * |
||
| 633 | * @param string $color The color. |
||
| 634 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 635 | */ |
||
| 636 | public function setColor($color) { |
||
| 640 | |||
| 641 | /** |
||
| 642 | * Set the crop. |
||
| 643 | * |
||
| 644 | * @param boolean $crop The crop. |
||
| 645 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 646 | */ |
||
| 647 | public function setCrop($crop) { |
||
| 651 | |||
| 652 | /** |
||
| 653 | * Set the defer. |
||
| 654 | * |
||
| 655 | * @param boolean $defer The defer. |
||
| 656 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 657 | */ |
||
| 658 | public function setDefer($defer) { |
||
| 662 | |||
| 663 | /** |
||
| 664 | * Set the enabled. |
||
| 665 | * |
||
| 666 | * @param boolean $enabled The enabled. |
||
| 667 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 668 | */ |
||
| 669 | public function setEnabled($enabled) { |
||
| 673 | |||
| 674 | /** |
||
| 675 | * Set the format. |
||
| 676 | * |
||
| 677 | * @param string $format The format. |
||
| 678 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 679 | */ |
||
| 680 | public function setFormat($format) { |
||
| 684 | |||
| 685 | /** |
||
| 686 | * Set the formatter. |
||
| 687 | * |
||
| 688 | * @param string $formatter The formatter. |
||
| 689 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 690 | */ |
||
| 691 | public function setFormatter($formatter) { |
||
| 695 | |||
| 696 | /** |
||
| 697 | * Set the inside. |
||
| 698 | * |
||
| 699 | * @param boolean $inside The inside. |
||
| 700 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 701 | */ |
||
| 702 | public function setInside($inside) { |
||
| 706 | |||
| 707 | /** |
||
| 708 | * Set the overflow. |
||
| 709 | * |
||
| 710 | * @param string $overflow The overflow. |
||
| 711 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 712 | */ |
||
| 713 | public function setOverflow($overflow) { |
||
| 722 | |||
| 723 | /** |
||
| 724 | * Set the padding. |
||
| 725 | * |
||
| 726 | * @param integer $padding The padding. |
||
| 727 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 728 | */ |
||
| 729 | public function setPadding($padding) { |
||
| 733 | |||
| 734 | /** |
||
| 735 | * Set the rotation. |
||
| 736 | * |
||
| 737 | * @param integer $rotation The rotation. |
||
| 738 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 739 | */ |
||
| 740 | public function setRotation($rotation) { |
||
| 744 | |||
| 745 | /** |
||
| 746 | * Set the shadow. |
||
| 747 | * |
||
| 748 | * @param boolean|array $shadow The shadow. |
||
| 749 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 750 | */ |
||
| 751 | public function setShadow($shadow) { |
||
| 755 | |||
| 756 | /** |
||
| 757 | * Set the shape. |
||
| 758 | * |
||
| 759 | * @param string $shape The shape. |
||
| 760 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 761 | */ |
||
| 762 | public function setShape($shape) { |
||
| 766 | |||
| 767 | /** |
||
| 768 | * Set the style. |
||
| 769 | * |
||
| 770 | * @param array $style The style. |
||
| 771 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 772 | */ |
||
| 773 | public function setStyle(array $style = null) { |
||
| 777 | |||
| 778 | /** |
||
| 779 | * Set the use HTML. |
||
| 780 | * |
||
| 781 | * @param boolean $useHTML The use HTML. |
||
| 782 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 783 | */ |
||
| 784 | public function setUseHTML($useHTML) { |
||
| 788 | |||
| 789 | /** |
||
| 790 | * Set the vertical align. |
||
| 791 | * |
||
| 792 | * @param string $verticalAlign The vertical align. |
||
| 793 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 794 | */ |
||
| 795 | public function setVerticalAlign($verticalAlign) { |
||
| 805 | |||
| 806 | /** |
||
| 807 | * Set the x. |
||
| 808 | * |
||
| 809 | * @param integer $x The x. |
||
| 810 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 811 | */ |
||
| 812 | public function setX($x) { |
||
| 816 | |||
| 817 | /** |
||
| 818 | * Set the y. |
||
| 819 | * |
||
| 820 | * @param integer $y The y. |
||
| 821 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 822 | */ |
||
| 823 | public function setY($y) { |
||
| 827 | |||
| 828 | /** |
||
| 829 | * Set the z index. |
||
| 830 | * |
||
| 831 | * @param integer $zIndex The z index. |
||
| 832 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\PlotOptions\Waterfall\HighchartsDataLabels Returns the highcharts data labels. |
||
| 833 | */ |
||
| 834 | public function setZIndex($zIndex) { |
||
| 838 | |||
| 839 | /** |
||
| 840 | * Convert into an array representing this instance. |
||
| 841 | * |
||
| 842 | * @return array Returns an array representing this instance. |
||
| 843 | */ |
||
| 844 | public function toArray() { |
||
| 927 | |||
| 928 | } |
||
| 929 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..