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 | * Class name. |
||
29 | * |
||
30 | * @var string |
||
31 | * @since 5.0.0 |
||
32 | */ |
||
33 | private $className; |
||
34 | |||
35 | /** |
||
36 | * Color. |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | private $color; |
||
41 | |||
42 | /** |
||
43 | * Color index. |
||
44 | * |
||
45 | * @var integer |
||
46 | * @since 5.0.0 |
||
47 | */ |
||
48 | private $colorIndex; |
||
49 | |||
50 | /** |
||
51 | * Data labels. |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | private $dataLabels; |
||
56 | |||
57 | /** |
||
58 | * Description. |
||
59 | * |
||
60 | * @var string |
||
61 | * @since 5.0.0 |
||
62 | */ |
||
63 | private $description; |
||
64 | |||
65 | /** |
||
66 | * Drilldown. |
||
67 | * |
||
68 | * @var string |
||
69 | * @since 3.0.8 |
||
70 | */ |
||
71 | private $drilldown; |
||
72 | |||
73 | /** |
||
74 | * Events. |
||
75 | * |
||
76 | * @var \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\Data\HighchartsEvents |
||
77 | */ |
||
78 | private $events; |
||
79 | |||
80 | /** |
||
81 | * High. |
||
82 | * |
||
83 | * @var integer |
||
84 | */ |
||
85 | private $high; |
||
86 | |||
87 | /** |
||
88 | * Id. |
||
89 | * |
||
90 | * @var string |
||
91 | * @since 1.2.0 |
||
92 | */ |
||
93 | private $id; |
||
94 | |||
95 | /** |
||
96 | * Labelrank. |
||
97 | * |
||
98 | * @var integer |
||
99 | */ |
||
100 | private $labelrank; |
||
101 | |||
102 | /** |
||
103 | * Low. |
||
104 | * |
||
105 | * @var integer |
||
106 | */ |
||
107 | private $low; |
||
108 | |||
109 | /** |
||
110 | * Median. |
||
111 | * |
||
112 | * @var integer |
||
113 | */ |
||
114 | private $median; |
||
115 | |||
116 | /** |
||
117 | * Name. |
||
118 | * |
||
119 | * @var string |
||
120 | */ |
||
121 | private $name; |
||
122 | |||
123 | /** |
||
124 | * Q1. |
||
125 | * |
||
126 | * @var integer |
||
127 | */ |
||
128 | private $q1; |
||
129 | |||
130 | /** |
||
131 | * Q3. |
||
132 | * |
||
133 | * @var integer |
||
134 | */ |
||
135 | private $q3; |
||
136 | |||
137 | /** |
||
138 | * Selected. |
||
139 | * |
||
140 | * @var boolean |
||
141 | */ |
||
142 | private $selected = false; |
||
143 | |||
144 | /** |
||
145 | * X. |
||
146 | * |
||
147 | * @var integer |
||
148 | */ |
||
149 | private $x; |
||
150 | |||
151 | /** |
||
152 | * Y. |
||
153 | * |
||
154 | * @var integer |
||
155 | */ |
||
156 | private $y; |
||
157 | |||
158 | /** |
||
159 | * Constructor. |
||
160 | * |
||
161 | * @param boolean $ignoreDefaultValues Ignore the default values. |
||
162 | */ |
||
163 | public function __construct($ignoreDefaultValues = true) { |
||
168 | |||
169 | /** |
||
170 | * Clear. |
||
171 | * |
||
172 | * @return void |
||
173 | */ |
||
174 | public function clear() { |
||
232 | |||
233 | /** |
||
234 | * Get the class name. |
||
235 | * |
||
236 | * @return string Returns the class name. |
||
237 | */ |
||
238 | public function getClassName() { |
||
241 | |||
242 | /** |
||
243 | * Get the color. |
||
244 | * |
||
245 | * @return string Returns the color. |
||
246 | */ |
||
247 | public function getColor() { |
||
250 | |||
251 | /** |
||
252 | * Get the color index. |
||
253 | * |
||
254 | * @return integer Returns the color index. |
||
255 | */ |
||
256 | public function getColorIndex() { |
||
259 | |||
260 | /** |
||
261 | * Get the data labels. |
||
262 | * |
||
263 | * @return array Returns the data labels. |
||
264 | */ |
||
265 | public function getDataLabels() { |
||
268 | |||
269 | /** |
||
270 | * Get the description. |
||
271 | * |
||
272 | * @return string Returns the description. |
||
273 | */ |
||
274 | public function getDescription() { |
||
277 | |||
278 | /** |
||
279 | * Get the drilldown. |
||
280 | * |
||
281 | * @return string Returns the drilldown. |
||
282 | */ |
||
283 | public function getDrilldown() { |
||
286 | |||
287 | /** |
||
288 | * Get the events. |
||
289 | * |
||
290 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\Data\HighchartsEvents Returns the events. |
||
291 | */ |
||
292 | public function getEvents() { |
||
295 | |||
296 | /** |
||
297 | * Get the high. |
||
298 | * |
||
299 | * @return integer Returns the high. |
||
300 | */ |
||
301 | public function getHigh() { |
||
304 | |||
305 | /** |
||
306 | * Get the id. |
||
307 | * |
||
308 | * @return string Returns the id. |
||
309 | */ |
||
310 | public function getId() { |
||
313 | |||
314 | /** |
||
315 | * Get the labelrank. |
||
316 | * |
||
317 | * @return integer Returns the labelrank. |
||
318 | */ |
||
319 | public function getLabelrank() { |
||
322 | |||
323 | /** |
||
324 | * Get the low. |
||
325 | * |
||
326 | * @return integer Returns the low. |
||
327 | */ |
||
328 | public function getLow() { |
||
331 | |||
332 | /** |
||
333 | * Get the median. |
||
334 | * |
||
335 | * @return integer Returns the median. |
||
336 | */ |
||
337 | public function getMedian() { |
||
340 | |||
341 | /** |
||
342 | * Get the name. |
||
343 | * |
||
344 | * @return string Returns the name. |
||
345 | */ |
||
346 | public function getName() { |
||
349 | |||
350 | /** |
||
351 | * Get the q1. |
||
352 | * |
||
353 | * @return integer Returns the q1. |
||
354 | */ |
||
355 | public function getQ1() { |
||
358 | |||
359 | /** |
||
360 | * Get the q3. |
||
361 | * |
||
362 | * @return integer Returns the q3. |
||
363 | */ |
||
364 | public function getQ3() { |
||
367 | |||
368 | /** |
||
369 | * Get the selected. |
||
370 | * |
||
371 | * @return boolean Returns the selected. |
||
372 | */ |
||
373 | public function getSelected() { |
||
376 | |||
377 | /** |
||
378 | * Get the x. |
||
379 | * |
||
380 | * @return integer Returns the x. |
||
381 | */ |
||
382 | public function getX() { |
||
385 | |||
386 | /** |
||
387 | * Get the y. |
||
388 | * |
||
389 | * @return integer Returns the y. |
||
390 | */ |
||
391 | public function getY() { |
||
394 | |||
395 | /** |
||
396 | * Serialize this instance. |
||
397 | * |
||
398 | * @return array Returns an array representing this instance. |
||
399 | */ |
||
400 | public function jsonSerialize() { |
||
403 | |||
404 | /** |
||
405 | * Create a new events. |
||
406 | * |
||
407 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\Data\HighchartsEvents Returns the events. |
||
408 | */ |
||
409 | public function newEvents() { |
||
413 | |||
414 | /** |
||
415 | * Set the class name. |
||
416 | * |
||
417 | * @param string $className The class name. |
||
418 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\HighchartsData Returns the highcharts data. |
||
419 | */ |
||
420 | public function setClassName($className) { |
||
424 | |||
425 | /** |
||
426 | * Set the color. |
||
427 | * |
||
428 | * @param string $color The color. |
||
429 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\HighchartsData Returns the highcharts data. |
||
430 | */ |
||
431 | public function setColor($color) { |
||
435 | |||
436 | /** |
||
437 | * Set the color index. |
||
438 | * |
||
439 | * @param integer $colorIndex The color index. |
||
440 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\HighchartsData Returns the highcharts data. |
||
441 | */ |
||
442 | public function setColorIndex($colorIndex) { |
||
446 | |||
447 | /** |
||
448 | * Set the data labels. |
||
449 | * |
||
450 | * @param array $dataLabels The data labels. |
||
451 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\HighchartsData Returns the highcharts data. |
||
452 | */ |
||
453 | public function setDataLabels(array $dataLabels = null) { |
||
457 | |||
458 | /** |
||
459 | * Set the description. |
||
460 | * |
||
461 | * @param string $description The description. |
||
462 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\HighchartsData Returns the highcharts data. |
||
463 | */ |
||
464 | public function setDescription($description) { |
||
468 | |||
469 | /** |
||
470 | * Set the drilldown. |
||
471 | * |
||
472 | * @param string $drilldown The drilldown. |
||
473 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\HighchartsData Returns the highcharts data. |
||
474 | */ |
||
475 | public function setDrilldown($drilldown) { |
||
479 | |||
480 | /** |
||
481 | * Set the events. |
||
482 | * |
||
483 | * @param \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\Data\HighchartsEvents $events The events. |
||
484 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\HighchartsData Returns the highcharts data. |
||
485 | */ |
||
486 | public function setEvents(\WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\Data\HighchartsEvents $events = null) { |
||
490 | |||
491 | /** |
||
492 | * Set the high. |
||
493 | * |
||
494 | * @param integer $high The high. |
||
495 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\HighchartsData Returns the highcharts data. |
||
496 | */ |
||
497 | public function setHigh($high) { |
||
501 | |||
502 | /** |
||
503 | * Set the id. |
||
504 | * |
||
505 | * @param string $id The id. |
||
506 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\HighchartsData Returns the highcharts data. |
||
507 | */ |
||
508 | public function setId($id) { |
||
512 | |||
513 | /** |
||
514 | * Set the labelrank. |
||
515 | * |
||
516 | * @param integer $labelrank The labelrank. |
||
517 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\HighchartsData Returns the highcharts data. |
||
518 | */ |
||
519 | public function setLabelrank($labelrank) { |
||
523 | |||
524 | /** |
||
525 | * Set the low. |
||
526 | * |
||
527 | * @param integer $low The low. |
||
528 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\HighchartsData Returns the highcharts data. |
||
529 | */ |
||
530 | public function setLow($low) { |
||
534 | |||
535 | /** |
||
536 | * Set the median. |
||
537 | * |
||
538 | * @param integer $median The median. |
||
539 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\HighchartsData Returns the highcharts data. |
||
540 | */ |
||
541 | public function setMedian($median) { |
||
545 | |||
546 | /** |
||
547 | * Set the name. |
||
548 | * |
||
549 | * @param string $name The name. |
||
550 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\HighchartsData Returns the highcharts data. |
||
551 | */ |
||
552 | public function setName($name) { |
||
556 | |||
557 | /** |
||
558 | * Set the q1. |
||
559 | * |
||
560 | * @param integer $q1 The q1. |
||
561 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\HighchartsData Returns the highcharts data. |
||
562 | */ |
||
563 | public function setQ1($q1) { |
||
567 | |||
568 | /** |
||
569 | * Set the q3. |
||
570 | * |
||
571 | * @param integer $q3 The q3. |
||
572 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\HighchartsData Returns the highcharts data. |
||
573 | */ |
||
574 | public function setQ3($q3) { |
||
578 | |||
579 | /** |
||
580 | * Set the selected. |
||
581 | * |
||
582 | * @param boolean $selected The selected. |
||
583 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\HighchartsData Returns the highcharts data. |
||
584 | */ |
||
585 | public function setSelected($selected) { |
||
589 | |||
590 | /** |
||
591 | * Set the x. |
||
592 | * |
||
593 | * @param integer $x The x. |
||
594 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\HighchartsData Returns the highcharts data. |
||
595 | */ |
||
596 | public function setX($x) { |
||
600 | |||
601 | /** |
||
602 | * Set the y. |
||
603 | * |
||
604 | * @param integer $y The y. |
||
605 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Series\Boxplot\HighchartsData Returns the highcharts data. |
||
606 | */ |
||
607 | public function setY($y) { |
||
611 | |||
612 | /** |
||
613 | * Convert into an array representing this instance. |
||
614 | * |
||
615 | * @return array Returns an array representing this instance. |
||
616 | */ |
||
617 | public function toArray() { |
||
681 | |||
682 | } |
||
683 |
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..