Complex classes like HighchartsExporting 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 HighchartsExporting, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | final class HighchartsExporting implements JsonSerializable { |
||
26 | |||
27 | /** |
||
28 | * Allow HTML. |
||
29 | * |
||
30 | * @var boolean |
||
31 | * @since 4.1.8 |
||
32 | */ |
||
33 | private $allowHTML = false; |
||
34 | |||
35 | /** |
||
36 | * Buttons. |
||
37 | * |
||
38 | * @var \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\HighchartsButtons |
||
39 | */ |
||
40 | private $buttons; |
||
41 | |||
42 | /** |
||
43 | * Chart options. |
||
44 | * |
||
45 | * @var array |
||
46 | */ |
||
47 | private $chartOptions; |
||
48 | |||
49 | /** |
||
50 | * Enabled. |
||
51 | * |
||
52 | * @var boolean |
||
53 | * @since 2.0 |
||
54 | */ |
||
55 | private $enabled = true; |
||
56 | |||
57 | /** |
||
58 | * Error. |
||
59 | * |
||
60 | * @var string |
||
61 | * @since 5.0.0 |
||
62 | */ |
||
63 | private $error; |
||
64 | |||
65 | /** |
||
66 | * Fallback to export server. |
||
67 | * |
||
68 | * @var boolean |
||
69 | * @since 4.1.8 |
||
70 | */ |
||
71 | private $fallbackToExportServer = true; |
||
72 | |||
73 | /** |
||
74 | * Filename. |
||
75 | * |
||
76 | * @var string |
||
77 | * @since 2.0 |
||
78 | */ |
||
79 | private $filename = "chart"; |
||
80 | |||
81 | /** |
||
82 | * Form attributes. |
||
83 | * |
||
84 | * @var array |
||
85 | * @since 3.0.8 |
||
86 | */ |
||
87 | private $formAttributes; |
||
88 | |||
89 | /** |
||
90 | * Lib URL. |
||
91 | * |
||
92 | * @var string |
||
93 | * @since 5.0.0 |
||
94 | */ |
||
95 | private $libURL = "https://code.highcharts.com/{version}/lib"; |
||
96 | |||
97 | /** |
||
98 | * Menu item definitions. |
||
99 | * |
||
100 | * @var array |
||
101 | * @since 5.0.13 |
||
102 | */ |
||
103 | private $menuItemDefinitions; |
||
104 | |||
105 | /** |
||
106 | * Print max width. |
||
107 | * |
||
108 | * @var integer |
||
109 | * @since 4.2.5 |
||
110 | */ |
||
111 | private $printMaxWidth = 780; |
||
112 | |||
113 | /** |
||
114 | * Scale. |
||
115 | * |
||
116 | * @var integer |
||
117 | * @since 3.0 |
||
118 | */ |
||
119 | private $scale = 2; |
||
120 | |||
121 | /** |
||
122 | * Source height. |
||
123 | * |
||
124 | * @var integer |
||
125 | * @since 3.0 |
||
126 | */ |
||
127 | private $sourceHeight; |
||
128 | |||
129 | /** |
||
130 | * Source width. |
||
131 | * |
||
132 | * @var integer |
||
133 | * @since 3.0 |
||
134 | */ |
||
135 | private $sourceWidth; |
||
136 | |||
137 | /** |
||
138 | * Type. |
||
139 | * |
||
140 | * @var string |
||
141 | * @since 2.0 |
||
142 | */ |
||
143 | private $type = "image/png"; |
||
144 | |||
145 | /** |
||
146 | * Url. |
||
147 | * |
||
148 | * @var string |
||
149 | * @since 2.0 |
||
150 | */ |
||
151 | private $url = "https://export.highcharts.com"; |
||
152 | |||
153 | /** |
||
154 | * Width. |
||
155 | * |
||
156 | * @var integer |
||
157 | * @since 2.0 |
||
158 | */ |
||
159 | private $width; |
||
160 | |||
161 | /** |
||
162 | * Constructor. |
||
163 | * |
||
164 | * @param boolean $ignoreDefaultValues Ignore the default values. |
||
165 | */ |
||
166 | public function __construct($ignoreDefaultValues = true) { |
||
171 | |||
172 | /** |
||
173 | * Clear. |
||
174 | * |
||
175 | * @return void |
||
176 | */ |
||
177 | public function clear() { |
||
232 | |||
233 | /** |
||
234 | * Get the allow HTML. |
||
235 | * |
||
236 | * @return boolean Returns the allow HTML. |
||
237 | */ |
||
238 | public function getAllowHTML() { |
||
241 | |||
242 | /** |
||
243 | * Get the buttons. |
||
244 | * |
||
245 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\HighchartsButtons Returns the buttons. |
||
246 | */ |
||
247 | public function getButtons() { |
||
250 | |||
251 | /** |
||
252 | * Get the chart options. |
||
253 | * |
||
254 | * @return array Returns the chart options. |
||
255 | */ |
||
256 | public function getChartOptions() { |
||
259 | |||
260 | /** |
||
261 | * Get the enabled. |
||
262 | * |
||
263 | * @return boolean Returns the enabled. |
||
264 | */ |
||
265 | public function getEnabled() { |
||
268 | |||
269 | /** |
||
270 | * Get the error. |
||
271 | * |
||
272 | * @return string Returns the error. |
||
273 | */ |
||
274 | public function getError() { |
||
277 | |||
278 | /** |
||
279 | * Get the fallback to export server. |
||
280 | * |
||
281 | * @return boolean Returns the fallback to export server. |
||
282 | */ |
||
283 | public function getFallbackToExportServer() { |
||
286 | |||
287 | /** |
||
288 | * Get the filename. |
||
289 | * |
||
290 | * @return string Returns the filename. |
||
291 | */ |
||
292 | public function getFilename() { |
||
295 | |||
296 | /** |
||
297 | * Get the form attributes. |
||
298 | * |
||
299 | * @return array Returns the form attributes. |
||
300 | */ |
||
301 | public function getFormAttributes() { |
||
304 | |||
305 | /** |
||
306 | * Get the lib URL. |
||
307 | * |
||
308 | * @return string Returns the lib URL. |
||
309 | */ |
||
310 | public function getLibURL() { |
||
313 | |||
314 | /** |
||
315 | * Get the menu item definitions. |
||
316 | * |
||
317 | * @return array Returns the menu item definitions. |
||
318 | */ |
||
319 | public function getMenuItemDefinitions() { |
||
322 | |||
323 | /** |
||
324 | * Get the print max width. |
||
325 | * |
||
326 | * @return integer Returns the print max width. |
||
327 | */ |
||
328 | public function getPrintMaxWidth() { |
||
331 | |||
332 | /** |
||
333 | * Get the scale. |
||
334 | * |
||
335 | * @return integer Returns the scale. |
||
336 | */ |
||
337 | public function getScale() { |
||
340 | |||
341 | /** |
||
342 | * Get the source height. |
||
343 | * |
||
344 | * @return integer Returns the source height. |
||
345 | */ |
||
346 | public function getSourceHeight() { |
||
349 | |||
350 | /** |
||
351 | * Get the source width. |
||
352 | * |
||
353 | * @return integer Returns the source width. |
||
354 | */ |
||
355 | public function getSourceWidth() { |
||
358 | |||
359 | /** |
||
360 | * Get the type. |
||
361 | * |
||
362 | * @return string Returns the type. |
||
363 | */ |
||
364 | public function getType() { |
||
367 | |||
368 | /** |
||
369 | * Get the url. |
||
370 | * |
||
371 | * @return string Returns the url. |
||
372 | */ |
||
373 | public function getUrl() { |
||
376 | |||
377 | /** |
||
378 | * Get the width. |
||
379 | * |
||
380 | * @return integer Returns the width. |
||
381 | */ |
||
382 | public function getWidth() { |
||
385 | |||
386 | /** |
||
387 | * Serialize this instance. |
||
388 | * |
||
389 | * @return array Returns an array representing this instance. |
||
390 | */ |
||
391 | public function jsonSerialize() { |
||
394 | |||
395 | /** |
||
396 | * Create a new buttons. |
||
397 | * |
||
398 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\HighchartsButtons Returns the buttons. |
||
399 | */ |
||
400 | public function newButtons() { |
||
404 | |||
405 | /** |
||
406 | * Set the allow HTML. |
||
407 | * |
||
408 | * @param boolean $allowHTML The allow HTML. |
||
409 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsExporting Returns the highcharts exporting. |
||
410 | */ |
||
411 | public function setAllowHTML($allowHTML) { |
||
415 | |||
416 | /** |
||
417 | * Set the buttons. |
||
418 | * |
||
419 | * @param \WBW\Bundle\HighchartsBundle\API\Chart\Exporting\HighchartsButtons $buttons The buttons. |
||
420 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsExporting Returns the highcharts exporting. |
||
421 | */ |
||
422 | public function setButtons(\WBW\Bundle\HighchartsBundle\API\Chart\Exporting\HighchartsButtons $buttons = null) { |
||
426 | |||
427 | /** |
||
428 | * Set the chart options. |
||
429 | * |
||
430 | * @param array $chartOptions The chart options. |
||
431 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsExporting Returns the highcharts exporting. |
||
432 | */ |
||
433 | public function setChartOptions(array $chartOptions = null) { |
||
437 | |||
438 | /** |
||
439 | * Set the enabled. |
||
440 | * |
||
441 | * @param boolean $enabled The enabled. |
||
442 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsExporting Returns the highcharts exporting. |
||
443 | */ |
||
444 | public function setEnabled($enabled) { |
||
448 | |||
449 | /** |
||
450 | * Set the error. |
||
451 | * |
||
452 | * @param string $error The error. |
||
453 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsExporting Returns the highcharts exporting. |
||
454 | */ |
||
455 | public function setError($error) { |
||
459 | |||
460 | /** |
||
461 | * Set the fallback to export server. |
||
462 | * |
||
463 | * @param boolean $fallbackToExportServer The fallback to export server. |
||
464 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsExporting Returns the highcharts exporting. |
||
465 | */ |
||
466 | public function setFallbackToExportServer($fallbackToExportServer) { |
||
470 | |||
471 | /** |
||
472 | * Set the filename. |
||
473 | * |
||
474 | * @param string $filename The filename. |
||
475 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsExporting Returns the highcharts exporting. |
||
476 | */ |
||
477 | public function setFilename($filename) { |
||
481 | |||
482 | /** |
||
483 | * Set the form attributes. |
||
484 | * |
||
485 | * @param array $formAttributes The form attributes. |
||
486 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsExporting Returns the highcharts exporting. |
||
487 | */ |
||
488 | public function setFormAttributes(array $formAttributes = null) { |
||
492 | |||
493 | /** |
||
494 | * Set the lib URL. |
||
495 | * |
||
496 | * @param string $libURL The lib URL. |
||
497 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsExporting Returns the highcharts exporting. |
||
498 | */ |
||
499 | public function setLibURL($libURL) { |
||
503 | |||
504 | /** |
||
505 | * Set the menu item definitions. |
||
506 | * |
||
507 | * @param array $menuItemDefinitions The menu item definitions. |
||
508 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsExporting Returns the highcharts exporting. |
||
509 | */ |
||
510 | public function setMenuItemDefinitions(array $menuItemDefinitions = null) { |
||
514 | |||
515 | /** |
||
516 | * Set the print max width. |
||
517 | * |
||
518 | * @param integer $printMaxWidth The print max width. |
||
519 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsExporting Returns the highcharts exporting. |
||
520 | */ |
||
521 | public function setPrintMaxWidth($printMaxWidth) { |
||
525 | |||
526 | /** |
||
527 | * Set the scale. |
||
528 | * |
||
529 | * @param integer $scale The scale. |
||
530 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsExporting Returns the highcharts exporting. |
||
531 | */ |
||
532 | public function setScale($scale) { |
||
536 | |||
537 | /** |
||
538 | * Set the source height. |
||
539 | * |
||
540 | * @param integer $sourceHeight The source height. |
||
541 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsExporting Returns the highcharts exporting. |
||
542 | */ |
||
543 | public function setSourceHeight($sourceHeight) { |
||
547 | |||
548 | /** |
||
549 | * Set the source width. |
||
550 | * |
||
551 | * @param integer $sourceWidth The source width. |
||
552 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsExporting Returns the highcharts exporting. |
||
553 | */ |
||
554 | public function setSourceWidth($sourceWidth) { |
||
558 | |||
559 | /** |
||
560 | * Set the type. |
||
561 | * |
||
562 | * @param string $type The type. |
||
563 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsExporting Returns the highcharts exporting. |
||
564 | */ |
||
565 | public function setType($type) { |
||
576 | |||
577 | /** |
||
578 | * Set the url. |
||
579 | * |
||
580 | * @param string $url The url. |
||
581 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsExporting Returns the highcharts exporting. |
||
582 | */ |
||
583 | public function setUrl($url) { |
||
587 | |||
588 | /** |
||
589 | * Set the width. |
||
590 | * |
||
591 | * @param integer $width The width. |
||
592 | * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsExporting Returns the highcharts exporting. |
||
593 | */ |
||
594 | public function setWidth($width) { |
||
598 | |||
599 | /** |
||
600 | * Convert into an array representing this instance. |
||
601 | * |
||
602 | * @return array Returns an array representing this instance. |
||
603 | */ |
||
604 | public function toArray() { |
||
665 | |||
666 | } |
||
667 |
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..