Complex classes like HighchartsData 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 HighchartsData, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | final class HighchartsData implements JsonSerializable { |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Columns. |
||
| 29 | * |
||
| 30 | * @var array |
||
| 31 | * @since 4.0 |
||
| 32 | */ |
||
| 33 | private $columns; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Complete. |
||
| 37 | * |
||
| 38 | * @var string |
||
| 39 | * @since 4.0 |
||
| 40 | */ |
||
| 41 | private $complete; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Csv. |
||
| 45 | * |
||
| 46 | * @var string |
||
| 47 | * @since 4.0 |
||
| 48 | */ |
||
| 49 | private $csv; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Date format. |
||
| 53 | * |
||
| 54 | * @var string |
||
| 55 | * @since 4.0 |
||
| 56 | */ |
||
| 57 | private $dateFormat; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Decimal point. |
||
| 61 | * |
||
| 62 | * @var string |
||
| 63 | * @since 4.1.0 |
||
| 64 | */ |
||
| 65 | private $decimalPoint = "."; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * End column. |
||
| 69 | * |
||
| 70 | * @var integer |
||
| 71 | * @since 4.0 |
||
| 72 | */ |
||
| 73 | private $endColumn; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * End row. |
||
| 77 | * |
||
| 78 | * @var integer |
||
| 79 | * @since 4.0.4 |
||
| 80 | */ |
||
| 81 | private $endRow; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * First row as names. |
||
| 85 | * |
||
| 86 | * @var boolean |
||
| 87 | * @since 4.1.0 |
||
| 88 | */ |
||
| 89 | private $firstRowAsNames = true; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Google spreadsheet key. |
||
| 93 | * |
||
| 94 | * @var string |
||
| 95 | * @since 4.0 |
||
| 96 | */ |
||
| 97 | private $googleSpreadsheetKey; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Google spreadsheet worksheet. |
||
| 101 | * |
||
| 102 | * @var string |
||
| 103 | * @since 4.0 |
||
| 104 | */ |
||
| 105 | private $googleSpreadsheetWorksheet; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Item delimiter. |
||
| 109 | * |
||
| 110 | * @var string |
||
| 111 | * @since 4.0 |
||
| 112 | */ |
||
| 113 | private $itemDelimiter; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Line delimiter. |
||
| 117 | * |
||
| 118 | * @var string |
||
| 119 | * @since 4.0 |
||
| 120 | */ |
||
| 121 | private $lineDelimiter = "\\n"; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Parse date. |
||
| 125 | * |
||
| 126 | * @var string |
||
| 127 | * @since 4.0 |
||
| 128 | */ |
||
| 129 | private $parseDate; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Parsed. |
||
| 133 | * |
||
| 134 | * @var string |
||
| 135 | * @since 4.0 |
||
| 136 | */ |
||
| 137 | private $parsed; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Rows. |
||
| 141 | * |
||
| 142 | * @var array |
||
| 143 | * @since 4.0 |
||
| 144 | */ |
||
| 145 | private $rows; |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Series mapping. |
||
| 149 | * |
||
| 150 | * @var array |
||
| 151 | * @since 4.0.4 |
||
| 152 | */ |
||
| 153 | private $seriesMapping; |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Start column. |
||
| 157 | * |
||
| 158 | * @var integer |
||
| 159 | * @since 4.0 |
||
| 160 | */ |
||
| 161 | private $startColumn = 0; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Start row. |
||
| 165 | * |
||
| 166 | * @var integer |
||
| 167 | * @since 4.0 |
||
| 168 | */ |
||
| 169 | private $startRow = 0; |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Switch rows and columns. |
||
| 173 | * |
||
| 174 | * @var boolean |
||
| 175 | * @since 4.0 |
||
| 176 | */ |
||
| 177 | private $switchRowsAndColumns = false; |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Table. |
||
| 181 | * |
||
| 182 | * @var string |
||
| 183 | * @since 4.0 |
||
| 184 | */ |
||
| 185 | private $table; |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Constructor. |
||
| 189 | * |
||
| 190 | * @param boolean $ignoreDefaultValues Ignore the default values. |
||
| 191 | */ |
||
| 192 | public function __construct($ignoreDefaultValues = true) { |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Clear. |
||
| 200 | * |
||
| 201 | * @return void |
||
| 202 | */ |
||
| 203 | public function clear() { |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Get the columns. |
||
| 268 | * |
||
| 269 | * @return array Returns the columns. |
||
| 270 | */ |
||
| 271 | public function getColumns() { |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Get the complete. |
||
| 277 | * |
||
| 278 | * @return string Returns the complete. |
||
| 279 | */ |
||
| 280 | public function getComplete() { |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Get the csv. |
||
| 286 | * |
||
| 287 | * @return string Returns the csv. |
||
| 288 | */ |
||
| 289 | public function getCsv() { |
||
| 292 | |||
| 293 | /** |
||
| 294 | * Get the date format. |
||
| 295 | * |
||
| 296 | * @return string Returns the date format. |
||
| 297 | */ |
||
| 298 | public function getDateFormat() { |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Get the decimal point. |
||
| 304 | * |
||
| 305 | * @return string Returns the decimal point. |
||
| 306 | */ |
||
| 307 | public function getDecimalPoint() { |
||
| 310 | |||
| 311 | /** |
||
| 312 | * Get the end column. |
||
| 313 | * |
||
| 314 | * @return integer Returns the end column. |
||
| 315 | */ |
||
| 316 | public function getEndColumn() { |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Get the end row. |
||
| 322 | * |
||
| 323 | * @return integer Returns the end row. |
||
| 324 | */ |
||
| 325 | public function getEndRow() { |
||
| 328 | |||
| 329 | /** |
||
| 330 | * Get the first row as names. |
||
| 331 | * |
||
| 332 | * @return boolean Returns the first row as names. |
||
| 333 | */ |
||
| 334 | public function getFirstRowAsNames() { |
||
| 337 | |||
| 338 | /** |
||
| 339 | * Get the google spreadsheet key. |
||
| 340 | * |
||
| 341 | * @return string Returns the google spreadsheet key. |
||
| 342 | */ |
||
| 343 | public function getGoogleSpreadsheetKey() { |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Get the google spreadsheet worksheet. |
||
| 349 | * |
||
| 350 | * @return string Returns the google spreadsheet worksheet. |
||
| 351 | */ |
||
| 352 | public function getGoogleSpreadsheetWorksheet() { |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Get the item delimiter. |
||
| 358 | * |
||
| 359 | * @return string Returns the item delimiter. |
||
| 360 | */ |
||
| 361 | public function getItemDelimiter() { |
||
| 364 | |||
| 365 | /** |
||
| 366 | * Get the line delimiter. |
||
| 367 | * |
||
| 368 | * @return string Returns the line delimiter. |
||
| 369 | */ |
||
| 370 | public function getLineDelimiter() { |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Get the parse date. |
||
| 376 | * |
||
| 377 | * @return string Returns the parse date. |
||
| 378 | */ |
||
| 379 | public function getParseDate() { |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Get the parsed. |
||
| 385 | * |
||
| 386 | * @return string Returns the parsed. |
||
| 387 | */ |
||
| 388 | public function getParsed() { |
||
| 391 | |||
| 392 | /** |
||
| 393 | * Get the rows. |
||
| 394 | * |
||
| 395 | * @return array Returns the rows. |
||
| 396 | */ |
||
| 397 | public function getRows() { |
||
| 400 | |||
| 401 | /** |
||
| 402 | * Get the series mapping. |
||
| 403 | * |
||
| 404 | * @return array Returns the series mapping. |
||
| 405 | */ |
||
| 406 | public function getSeriesMapping() { |
||
| 409 | |||
| 410 | /** |
||
| 411 | * Get the start column. |
||
| 412 | * |
||
| 413 | * @return integer Returns the start column. |
||
| 414 | */ |
||
| 415 | public function getStartColumn() { |
||
| 418 | |||
| 419 | /** |
||
| 420 | * Get the start row. |
||
| 421 | * |
||
| 422 | * @return integer Returns the start row. |
||
| 423 | */ |
||
| 424 | public function getStartRow() { |
||
| 427 | |||
| 428 | /** |
||
| 429 | * Get the switch rows and columns. |
||
| 430 | * |
||
| 431 | * @return boolean Returns the switch rows and columns. |
||
| 432 | */ |
||
| 433 | public function getSwitchRowsAndColumns() { |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Get the table. |
||
| 439 | * |
||
| 440 | * @return string Returns the table. |
||
| 441 | */ |
||
| 442 | public function getTable() { |
||
| 445 | |||
| 446 | /** |
||
| 447 | * Serialize this instance. |
||
| 448 | * |
||
| 449 | * @return array Returns an array representing this instance. |
||
| 450 | */ |
||
| 451 | public function jsonSerialize() { |
||
| 454 | |||
| 455 | /** |
||
| 456 | * Set the columns. |
||
| 457 | * |
||
| 458 | * @param array $columns The columns. |
||
| 459 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 460 | */ |
||
| 461 | public function setColumns(array $columns = null) { |
||
| 465 | |||
| 466 | /** |
||
| 467 | * Set the complete. |
||
| 468 | * |
||
| 469 | * @param string $complete The complete. |
||
| 470 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 471 | */ |
||
| 472 | public function setComplete($complete) { |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Set the csv. |
||
| 479 | * |
||
| 480 | * @param string $csv The csv. |
||
| 481 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 482 | */ |
||
| 483 | public function setCsv($csv) { |
||
| 487 | |||
| 488 | /** |
||
| 489 | * Set the date format. |
||
| 490 | * |
||
| 491 | * @param string $dateFormat The date format. |
||
| 492 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 493 | */ |
||
| 494 | public function setDateFormat($dateFormat) { |
||
| 508 | |||
| 509 | /** |
||
| 510 | * Set the decimal point. |
||
| 511 | * |
||
| 512 | * @param string $decimalPoint The decimal point. |
||
| 513 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 514 | */ |
||
| 515 | public function setDecimalPoint($decimalPoint) { |
||
| 519 | |||
| 520 | /** |
||
| 521 | * Set the end column. |
||
| 522 | * |
||
| 523 | * @param integer $endColumn The end column. |
||
| 524 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 525 | */ |
||
| 526 | public function setEndColumn($endColumn) { |
||
| 530 | |||
| 531 | /** |
||
| 532 | * Set the end row. |
||
| 533 | * |
||
| 534 | * @param integer $endRow The end row. |
||
| 535 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 536 | */ |
||
| 537 | public function setEndRow($endRow) { |
||
| 541 | |||
| 542 | /** |
||
| 543 | * Set the first row as names. |
||
| 544 | * |
||
| 545 | * @param boolean $firstRowAsNames The first row as names. |
||
| 546 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 547 | */ |
||
| 548 | public function setFirstRowAsNames($firstRowAsNames) { |
||
| 552 | |||
| 553 | /** |
||
| 554 | * Set the google spreadsheet key. |
||
| 555 | * |
||
| 556 | * @param string $googleSpreadsheetKey The google spreadsheet key. |
||
| 557 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 558 | */ |
||
| 559 | public function setGoogleSpreadsheetKey($googleSpreadsheetKey) { |
||
| 563 | |||
| 564 | /** |
||
| 565 | * Set the google spreadsheet worksheet. |
||
| 566 | * |
||
| 567 | * @param string $googleSpreadsheetWorksheet The google spreadsheet worksheet. |
||
| 568 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 569 | */ |
||
| 570 | public function setGoogleSpreadsheetWorksheet($googleSpreadsheetWorksheet) { |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Set the item delimiter. |
||
| 577 | * |
||
| 578 | * @param string $itemDelimiter The item delimiter. |
||
| 579 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 580 | */ |
||
| 581 | public function setItemDelimiter($itemDelimiter) { |
||
| 585 | |||
| 586 | /** |
||
| 587 | * Set the line delimiter. |
||
| 588 | * |
||
| 589 | * @param string $lineDelimiter The line delimiter. |
||
| 590 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 591 | */ |
||
| 592 | public function setLineDelimiter($lineDelimiter) { |
||
| 596 | |||
| 597 | /** |
||
| 598 | * Set the parse date. |
||
| 599 | * |
||
| 600 | * @param string $parseDate The parse date. |
||
| 601 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 602 | */ |
||
| 603 | public function setParseDate($parseDate) { |
||
| 607 | |||
| 608 | /** |
||
| 609 | * Set the parsed. |
||
| 610 | * |
||
| 611 | * @param string $parsed The parsed. |
||
| 612 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 613 | */ |
||
| 614 | public function setParsed($parsed) { |
||
| 618 | |||
| 619 | /** |
||
| 620 | * Set the rows. |
||
| 621 | * |
||
| 622 | * @param array $rows The rows. |
||
| 623 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 624 | */ |
||
| 625 | public function setRows(array $rows = null) { |
||
| 629 | |||
| 630 | /** |
||
| 631 | * Set the series mapping. |
||
| 632 | * |
||
| 633 | * @param array $seriesMapping The series mapping. |
||
| 634 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 635 | */ |
||
| 636 | public function setSeriesMapping(array $seriesMapping = null) { |
||
| 640 | |||
| 641 | /** |
||
| 642 | * Set the start column. |
||
| 643 | * |
||
| 644 | * @param integer $startColumn The start column. |
||
| 645 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 646 | */ |
||
| 647 | public function setStartColumn($startColumn) { |
||
| 651 | |||
| 652 | /** |
||
| 653 | * Set the start row. |
||
| 654 | * |
||
| 655 | * @param integer $startRow The start row. |
||
| 656 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 657 | */ |
||
| 658 | public function setStartRow($startRow) { |
||
| 662 | |||
| 663 | /** |
||
| 664 | * Set the switch rows and columns. |
||
| 665 | * |
||
| 666 | * @param boolean $switchRowsAndColumns The switch rows and columns. |
||
| 667 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 668 | */ |
||
| 669 | public function setSwitchRowsAndColumns($switchRowsAndColumns) { |
||
| 673 | |||
| 674 | /** |
||
| 675 | * Set the table. |
||
| 676 | * |
||
| 677 | * @param string $table The table. |
||
| 678 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsData Returns the highcharts data. |
||
| 679 | */ |
||
| 680 | public function setTable($table) { |
||
| 684 | |||
| 685 | /** |
||
| 686 | * Convert into an array representing this instance. |
||
| 687 | * |
||
| 688 | * @return array Returns an array representing this instance. |
||
| 689 | */ |
||
| 690 | public function toArray() { |
||
| 758 | |||
| 759 | } |
||
| 760 |
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..