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 = "left"; |
||
| 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 = 5; |
||
| 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\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 552 | */ |
||
| 553 | public function setAlign($align) { |
||
| 557 | |||
| 558 | /** |
||
| 559 | * Set the allow overlap. |
||
| 560 | * |
||
| 561 | * @param boolean $allowOverlap The allow overlap. |
||
| 562 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 563 | */ |
||
| 564 | public function setAllowOverlap($allowOverlap) { |
||
| 568 | |||
| 569 | /** |
||
| 570 | * Set the background color. |
||
| 571 | * |
||
| 572 | * @param string $backgroundColor The background color. |
||
| 573 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 574 | */ |
||
| 575 | public function setBackgroundColor($backgroundColor) { |
||
| 579 | |||
| 580 | /** |
||
| 581 | * Set the border color. |
||
| 582 | * |
||
| 583 | * @param string $borderColor The border color. |
||
| 584 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 585 | */ |
||
| 586 | public function setBorderColor($borderColor) { |
||
| 590 | |||
| 591 | /** |
||
| 592 | * Set the border radius. |
||
| 593 | * |
||
| 594 | * @param integer $borderRadius The border radius. |
||
| 595 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 596 | */ |
||
| 597 | public function setBorderRadius($borderRadius) { |
||
| 601 | |||
| 602 | /** |
||
| 603 | * Set the border width. |
||
| 604 | * |
||
| 605 | * @param integer $borderWidth The border width. |
||
| 606 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 607 | */ |
||
| 608 | public function setBorderWidth($borderWidth) { |
||
| 612 | |||
| 613 | /** |
||
| 614 | * Set the class name. |
||
| 615 | * |
||
| 616 | * @param string $className The class name. |
||
| 617 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 618 | */ |
||
| 619 | public function setClassName($className) { |
||
| 623 | |||
| 624 | /** |
||
| 625 | * Set the color. |
||
| 626 | * |
||
| 627 | * @param string $color The color. |
||
| 628 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 629 | */ |
||
| 630 | public function setColor($color) { |
||
| 634 | |||
| 635 | /** |
||
| 636 | * Set the crop. |
||
| 637 | * |
||
| 638 | * @param boolean $crop The crop. |
||
| 639 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 640 | */ |
||
| 641 | public function setCrop($crop) { |
||
| 645 | |||
| 646 | /** |
||
| 647 | * Set the defer. |
||
| 648 | * |
||
| 649 | * @param boolean $defer The defer. |
||
| 650 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 651 | */ |
||
| 652 | public function setDefer($defer) { |
||
| 656 | |||
| 657 | /** |
||
| 658 | * Set the enabled. |
||
| 659 | * |
||
| 660 | * @param boolean $enabled The enabled. |
||
| 661 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 662 | */ |
||
| 663 | public function setEnabled($enabled) { |
||
| 667 | |||
| 668 | /** |
||
| 669 | * Set the format. |
||
| 670 | * |
||
| 671 | * @param string $format The format. |
||
| 672 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 673 | */ |
||
| 674 | public function setFormat($format) { |
||
| 678 | |||
| 679 | /** |
||
| 680 | * Set the formatter. |
||
| 681 | * |
||
| 682 | * @param string $formatter The formatter. |
||
| 683 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 684 | */ |
||
| 685 | public function setFormatter($formatter) { |
||
| 689 | |||
| 690 | /** |
||
| 691 | * Set the inside. |
||
| 692 | * |
||
| 693 | * @param boolean $inside The inside. |
||
| 694 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 695 | */ |
||
| 696 | public function setInside($inside) { |
||
| 700 | |||
| 701 | /** |
||
| 702 | * Set the overflow. |
||
| 703 | * |
||
| 704 | * @param string $overflow The overflow. |
||
| 705 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 706 | */ |
||
| 707 | public function setOverflow($overflow) { |
||
| 716 | |||
| 717 | /** |
||
| 718 | * Set the padding. |
||
| 719 | * |
||
| 720 | * @param integer $padding The padding. |
||
| 721 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 722 | */ |
||
| 723 | public function setPadding($padding) { |
||
| 727 | |||
| 728 | /** |
||
| 729 | * Set the rotation. |
||
| 730 | * |
||
| 731 | * @param integer $rotation The rotation. |
||
| 732 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 733 | */ |
||
| 734 | public function setRotation($rotation) { |
||
| 738 | |||
| 739 | /** |
||
| 740 | * Set the shadow. |
||
| 741 | * |
||
| 742 | * @param boolean|array $shadow The shadow. |
||
| 743 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 744 | */ |
||
| 745 | public function setShadow($shadow) { |
||
| 749 | |||
| 750 | /** |
||
| 751 | * Set the shape. |
||
| 752 | * |
||
| 753 | * @param string $shape The shape. |
||
| 754 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 755 | */ |
||
| 756 | public function setShape($shape) { |
||
| 760 | |||
| 761 | /** |
||
| 762 | * Set the style. |
||
| 763 | * |
||
| 764 | * @param array $style The style. |
||
| 765 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 766 | */ |
||
| 767 | public function setStyle(array $style = null) { |
||
| 771 | |||
| 772 | /** |
||
| 773 | * Set the use HTML. |
||
| 774 | * |
||
| 775 | * @param boolean $useHTML The use HTML. |
||
| 776 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 777 | */ |
||
| 778 | public function setUseHTML($useHTML) { |
||
| 782 | |||
| 783 | /** |
||
| 784 | * Set the vertical align. |
||
| 785 | * |
||
| 786 | * @param string $verticalAlign The vertical align. |
||
| 787 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 788 | */ |
||
| 789 | public function setVerticalAlign($verticalAlign) { |
||
| 799 | |||
| 800 | /** |
||
| 801 | * Set the x. |
||
| 802 | * |
||
| 803 | * @param integer $x The x. |
||
| 804 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 805 | */ |
||
| 806 | public function setX($x) { |
||
| 810 | |||
| 811 | /** |
||
| 812 | * Set the y. |
||
| 813 | * |
||
| 814 | * @param integer $y The y. |
||
| 815 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 816 | */ |
||
| 817 | public function setY($y) { |
||
| 821 | |||
| 822 | /** |
||
| 823 | * Set the z index. |
||
| 824 | * |
||
| 825 | * @param integer $zIndex The z index. |
||
| 826 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Bar\HighchartsDataLabels Returns the highcharts data labels. |
||
| 827 | */ |
||
| 828 | public function setZIndex($zIndex) { |
||
| 832 | |||
| 833 | /** |
||
| 834 | * Convert into an array representing this instance. |
||
| 835 | * |
||
| 836 | * @return array Returns an array representing this instance. |
||
| 837 | */ |
||
| 838 | public function toArray() { |
||
| 921 | |||
| 922 | } |
||
| 923 |
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..