Complex classes like HighchartsContextButton 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 HighchartsContextButton, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | final class HighchartsContextButton implements JsonSerializable { |
||
26 | |||
27 | /** |
||
28 | * Align. |
||
29 | * |
||
30 | * @var string |
||
31 | * @since 2.0 |
||
32 | */ |
||
33 | private $align = "right"; |
||
34 | |||
35 | /** |
||
36 | * Enabled. |
||
37 | * |
||
38 | * @var boolean |
||
39 | * @since 2.0 |
||
40 | */ |
||
41 | private $enabled = true; |
||
42 | |||
43 | /** |
||
44 | * Height. |
||
45 | * |
||
46 | * @var integer |
||
47 | * @since 2.0 |
||
48 | */ |
||
49 | private $height = 20; |
||
50 | |||
51 | /** |
||
52 | * Menu items. |
||
53 | * |
||
54 | * @var array |
||
55 | * @since 2.0 |
||
56 | */ |
||
57 | private $menuItems; |
||
58 | |||
59 | /** |
||
60 | * Onclick. |
||
61 | * |
||
62 | * @var string |
||
63 | * @since 2.0 |
||
64 | */ |
||
65 | private $onclick; |
||
66 | |||
67 | /** |
||
68 | * Symbol. |
||
69 | * |
||
70 | * @var string |
||
71 | * @since 2.0 |
||
72 | */ |
||
73 | private $symbol = "menu"; |
||
74 | |||
75 | /** |
||
76 | * Symbol fill. |
||
77 | * |
||
78 | * @var string |
||
79 | * @since 2.0 |
||
80 | */ |
||
81 | private $symbolFill = "#666666"; |
||
82 | |||
83 | /** |
||
84 | * Symbol size. |
||
85 | * |
||
86 | * @var integer |
||
87 | * @since 2.0 |
||
88 | */ |
||
89 | private $symbolSize = 14; |
||
90 | |||
91 | /** |
||
92 | * Symbol stroke. |
||
93 | * |
||
94 | * @var string |
||
95 | * @since 2.0 |
||
96 | */ |
||
97 | private $symbolStroke = "#666666"; |
||
98 | |||
99 | /** |
||
100 | * Symbol stroke width. |
||
101 | * |
||
102 | * @var integer |
||
103 | * @since 2.0 |
||
104 | */ |
||
105 | private $symbolStrokeWidth = 1; |
||
106 | |||
107 | /** |
||
108 | * Symbol x. |
||
109 | * |
||
110 | * @var integer |
||
111 | * @since 2.0 |
||
112 | */ |
||
113 | private $symbolX = 12.5; |
||
114 | |||
115 | /** |
||
116 | * Symbol y. |
||
117 | * |
||
118 | * @var integer |
||
119 | * @since 2.0 |
||
120 | */ |
||
121 | private $symbolY = 10.5; |
||
122 | |||
123 | /** |
||
124 | * Text. |
||
125 | * |
||
126 | * @var string |
||
127 | * @since 3.0 |
||
128 | */ |
||
129 | private $text; |
||
130 | |||
131 | /** |
||
132 | * Theme. |
||
133 | * |
||
134 | * @var array |
||
135 | * @since 3.0 |
||
136 | */ |
||
137 | private $theme; |
||
138 | |||
139 | /** |
||
140 | * Vertical align. |
||
141 | * |
||
142 | * @var string |
||
143 | * @since 2.0 |
||
144 | */ |
||
145 | private $verticalAlign = "top"; |
||
146 | |||
147 | /** |
||
148 | * Width. |
||
149 | * |
||
150 | * @var integer |
||
151 | * @since 2.0 |
||
152 | */ |
||
153 | private $width = 24; |
||
154 | |||
155 | /** |
||
156 | * X. |
||
157 | * |
||
158 | * @var integer |
||
159 | * @since 2.0 |
||
160 | */ |
||
161 | private $x = -10; |
||
162 | |||
163 | /** |
||
164 | * Y. |
||
165 | * |
||
166 | * @var integer |
||
167 | * @since 2.0 |
||
168 | */ |
||
169 | private $y = 0; |
||
170 | |||
171 | /** |
||
172 | * Constructor. |
||
173 | * |
||
174 | * @param boolean $ignoreDefaultValues Ignore the default values. |
||
175 | */ |
||
176 | public function __construct($ignoreDefaultValues = true) { |
||
181 | |||
182 | /** |
||
183 | * Clear. |
||
184 | * |
||
185 | * @return void |
||
186 | */ |
||
187 | public function clear() { |
||
243 | |||
244 | /** |
||
245 | * Get the align. |
||
246 | * |
||
247 | * @return string Returns the align. |
||
248 | */ |
||
249 | public function getAlign() { |
||
252 | |||
253 | /** |
||
254 | * Get the enabled. |
||
255 | * |
||
256 | * @return boolean Returns the enabled. |
||
257 | */ |
||
258 | public function getEnabled() { |
||
261 | |||
262 | /** |
||
263 | * Get the height. |
||
264 | * |
||
265 | * @return integer Returns the height. |
||
266 | */ |
||
267 | public function getHeight() { |
||
270 | |||
271 | /** |
||
272 | * Get the menu items. |
||
273 | * |
||
274 | * @return array Returns the menu items. |
||
275 | */ |
||
276 | public function getMenuItems() { |
||
279 | |||
280 | /** |
||
281 | * Get the onclick. |
||
282 | * |
||
283 | * @return string Returns the onclick. |
||
284 | */ |
||
285 | public function getOnclick() { |
||
288 | |||
289 | /** |
||
290 | * Get the symbol. |
||
291 | * |
||
292 | * @return string Returns the symbol. |
||
293 | */ |
||
294 | public function getSymbol() { |
||
297 | |||
298 | /** |
||
299 | * Get the symbol fill. |
||
300 | * |
||
301 | * @return string Returns the symbol fill. |
||
302 | */ |
||
303 | public function getSymbolFill() { |
||
306 | |||
307 | /** |
||
308 | * Get the symbol size. |
||
309 | * |
||
310 | * @return integer Returns the symbol size. |
||
311 | */ |
||
312 | public function getSymbolSize() { |
||
315 | |||
316 | /** |
||
317 | * Get the symbol stroke. |
||
318 | * |
||
319 | * @return string Returns the symbol stroke. |
||
320 | */ |
||
321 | public function getSymbolStroke() { |
||
324 | |||
325 | /** |
||
326 | * Get the symbol stroke width. |
||
327 | * |
||
328 | * @return integer Returns the symbol stroke width. |
||
329 | */ |
||
330 | public function getSymbolStrokeWidth() { |
||
333 | |||
334 | /** |
||
335 | * Get the symbol x. |
||
336 | * |
||
337 | * @return integer Returns the symbol x. |
||
338 | */ |
||
339 | public function getSymbolX() { |
||
342 | |||
343 | /** |
||
344 | * Get the symbol y. |
||
345 | * |
||
346 | * @return integer Returns the symbol y. |
||
347 | */ |
||
348 | public function getSymbolY() { |
||
351 | |||
352 | /** |
||
353 | * Get the text. |
||
354 | * |
||
355 | * @return string Returns the text. |
||
356 | */ |
||
357 | public function getText() { |
||
360 | |||
361 | /** |
||
362 | * Get the theme. |
||
363 | * |
||
364 | * @return array Returns the theme. |
||
365 | */ |
||
366 | public function getTheme() { |
||
369 | |||
370 | /** |
||
371 | * Get the vertical align. |
||
372 | * |
||
373 | * @return string Returns the vertical align. |
||
374 | */ |
||
375 | public function getVerticalAlign() { |
||
378 | |||
379 | /** |
||
380 | * Get the width. |
||
381 | * |
||
382 | * @return integer Returns the width. |
||
383 | */ |
||
384 | public function getWidth() { |
||
387 | |||
388 | /** |
||
389 | * Get the x. |
||
390 | * |
||
391 | * @return integer Returns the x. |
||
392 | */ |
||
393 | public function getX() { |
||
396 | |||
397 | /** |
||
398 | * Get the y. |
||
399 | * |
||
400 | * @return integer Returns the y. |
||
401 | */ |
||
402 | public function getY() { |
||
405 | |||
406 | /** |
||
407 | * Serialize this instance. |
||
408 | * |
||
409 | * @return array Returns an array representing this instance. |
||
410 | */ |
||
411 | public function jsonSerialize() { |
||
414 | |||
415 | /** |
||
416 | * Set the align. |
||
417 | * |
||
418 | * @param string $align The align. |
||
419 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\Buttons\HighchartsContextButton Returns the highcharts context button. |
||
420 | */ |
||
421 | public function setAlign($align) { |
||
431 | |||
432 | /** |
||
433 | * Set the enabled. |
||
434 | * |
||
435 | * @param boolean $enabled The enabled. |
||
436 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\Buttons\HighchartsContextButton Returns the highcharts context button. |
||
437 | */ |
||
438 | public function setEnabled($enabled) { |
||
442 | |||
443 | /** |
||
444 | * Set the height. |
||
445 | * |
||
446 | * @param integer $height The height. |
||
447 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\Buttons\HighchartsContextButton Returns the highcharts context button. |
||
448 | */ |
||
449 | public function setHeight($height) { |
||
453 | |||
454 | /** |
||
455 | * Set the menu items. |
||
456 | * |
||
457 | * @param array $menuItems The menu items. |
||
458 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\Buttons\HighchartsContextButton Returns the highcharts context button. |
||
459 | */ |
||
460 | public function setMenuItems(array $menuItems = null) { |
||
464 | |||
465 | /** |
||
466 | * Set the onclick. |
||
467 | * |
||
468 | * @param string $onclick The onclick. |
||
469 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\Buttons\HighchartsContextButton Returns the highcharts context button. |
||
470 | */ |
||
471 | public function setOnclick($onclick) { |
||
475 | |||
476 | /** |
||
477 | * Set the symbol. |
||
478 | * |
||
479 | * @param string $symbol The symbol. |
||
480 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\Buttons\HighchartsContextButton Returns the highcharts context button. |
||
481 | */ |
||
482 | public function setSymbol($symbol) { |
||
495 | |||
496 | /** |
||
497 | * Set the symbol fill. |
||
498 | * |
||
499 | * @param string $symbolFill The symbol fill. |
||
500 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\Buttons\HighchartsContextButton Returns the highcharts context button. |
||
501 | */ |
||
502 | public function setSymbolFill($symbolFill) { |
||
506 | |||
507 | /** |
||
508 | * Set the symbol size. |
||
509 | * |
||
510 | * @param integer $symbolSize The symbol size. |
||
511 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\Buttons\HighchartsContextButton Returns the highcharts context button. |
||
512 | */ |
||
513 | public function setSymbolSize($symbolSize) { |
||
517 | |||
518 | /** |
||
519 | * Set the symbol stroke. |
||
520 | * |
||
521 | * @param string $symbolStroke The symbol stroke. |
||
522 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\Buttons\HighchartsContextButton Returns the highcharts context button. |
||
523 | */ |
||
524 | public function setSymbolStroke($symbolStroke) { |
||
528 | |||
529 | /** |
||
530 | * Set the symbol stroke width. |
||
531 | * |
||
532 | * @param integer $symbolStrokeWidth The symbol stroke width. |
||
533 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\Buttons\HighchartsContextButton Returns the highcharts context button. |
||
534 | */ |
||
535 | public function setSymbolStrokeWidth($symbolStrokeWidth) { |
||
539 | |||
540 | /** |
||
541 | * Set the symbol x. |
||
542 | * |
||
543 | * @param integer $symbolX The symbol x. |
||
544 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\Buttons\HighchartsContextButton Returns the highcharts context button. |
||
545 | */ |
||
546 | public function setSymbolX($symbolX) { |
||
550 | |||
551 | /** |
||
552 | * Set the symbol y. |
||
553 | * |
||
554 | * @param integer $symbolY The symbol y. |
||
555 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\Buttons\HighchartsContextButton Returns the highcharts context button. |
||
556 | */ |
||
557 | public function setSymbolY($symbolY) { |
||
561 | |||
562 | /** |
||
563 | * Set the text. |
||
564 | * |
||
565 | * @param string $text The text. |
||
566 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\Buttons\HighchartsContextButton Returns the highcharts context button. |
||
567 | */ |
||
568 | public function setText($text) { |
||
572 | |||
573 | /** |
||
574 | * Set the theme. |
||
575 | * |
||
576 | * @param array $theme The theme. |
||
577 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\Buttons\HighchartsContextButton Returns the highcharts context button. |
||
578 | */ |
||
579 | public function setTheme(array $theme = null) { |
||
583 | |||
584 | /** |
||
585 | * Set the vertical align. |
||
586 | * |
||
587 | * @param string $verticalAlign The vertical align. |
||
588 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\Buttons\HighchartsContextButton Returns the highcharts context button. |
||
589 | */ |
||
590 | public function setVerticalAlign($verticalAlign) { |
||
600 | |||
601 | /** |
||
602 | * Set the width. |
||
603 | * |
||
604 | * @param integer $width The width. |
||
605 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\Buttons\HighchartsContextButton Returns the highcharts context button. |
||
606 | */ |
||
607 | public function setWidth($width) { |
||
611 | |||
612 | /** |
||
613 | * Set the x. |
||
614 | * |
||
615 | * @param integer $x The x. |
||
616 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\Buttons\HighchartsContextButton Returns the highcharts context button. |
||
617 | */ |
||
618 | public function setX($x) { |
||
622 | |||
623 | /** |
||
624 | * Set the y. |
||
625 | * |
||
626 | * @param integer $y The y. |
||
627 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\Buttons\HighchartsContextButton Returns the highcharts context button. |
||
628 | */ |
||
629 | public function setY($y) { |
||
633 | |||
634 | /** |
||
635 | * Convert into an array representing this instance. |
||
636 | * |
||
637 | * @return array Returns an array representing this instance. |
||
638 | */ |
||
639 | public function toArray() { |
||
701 | |||
702 | } |
||
703 |
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..