Complex classes like AbstractChart 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 AbstractChart, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
9 | abstract class AbstractChart |
||
10 | { |
||
11 | protected static $chartOptions = [ |
||
12 | 'bindto', 'area', 'size', 'data', 'padding', 'color', 'interaction', 'transition', 'axis', 'gauge', |
||
13 | 'grid', 'region', 'legend', 'tootip', 'subchart', 'zoom', 'point', 'line', 'bar', 'pie', 'donut', 'tooltip', |
||
14 | 'title', |
||
15 | ]; |
||
16 | |||
17 | // Default options |
||
18 | public $bindto; |
||
19 | public $area; |
||
20 | public $size; |
||
21 | public $data; |
||
22 | public $padding; |
||
23 | public $color; |
||
24 | public $interaction; |
||
25 | public $transition; |
||
26 | public $axis; |
||
27 | public $grid; |
||
28 | public $region; |
||
29 | public $legend; |
||
30 | public $tooltip; |
||
31 | public $subchart; |
||
32 | public $zoom; |
||
33 | public $point; |
||
34 | public $line; |
||
35 | public $bar; |
||
36 | public $pie; |
||
37 | public $donut; |
||
38 | public $gauge; |
||
39 | public $title; |
||
40 | |||
41 | public function __construct() |
||
47 | |||
48 | abstract public function render(); |
||
49 | |||
50 | /** |
||
51 | * @param string $name |
||
52 | * @param array $args |
||
53 | * |
||
54 | * @return $this |
||
55 | */ |
||
56 | public function __call(string $name, array $args) |
||
62 | |||
63 | /** |
||
64 | * @param string $name |
||
65 | */ |
||
66 | protected function initChartOption(string $name) |
||
70 | |||
71 | /** |
||
72 | * @return string |
||
73 | */ |
||
74 | protected function renderBindTo(): string |
||
82 | |||
83 | /** |
||
84 | * @return string |
||
85 | */ |
||
86 | protected function renderArea(): string |
||
94 | |||
95 | /** |
||
96 | * @return string |
||
97 | */ |
||
98 | protected function renderSize(): string |
||
106 | |||
107 | /** |
||
108 | * @return string |
||
109 | */ |
||
110 | protected function renderData(): string |
||
118 | |||
119 | /** |
||
120 | * @return string |
||
121 | */ |
||
122 | protected function renderPadding(): string |
||
130 | |||
131 | /** |
||
132 | * @return string |
||
133 | */ |
||
134 | protected function renderColor(): string |
||
142 | |||
143 | /** |
||
144 | * @return string |
||
145 | */ |
||
146 | protected function renderInteraction(): string |
||
154 | |||
155 | /** |
||
156 | * @return string |
||
157 | */ |
||
158 | protected function renderTransition(): string |
||
166 | |||
167 | /** |
||
168 | * @return string |
||
169 | */ |
||
170 | protected function renderAxis(): string |
||
178 | |||
179 | /** |
||
180 | * @return string |
||
181 | */ |
||
182 | protected function renderGrid(): string |
||
190 | |||
191 | /** |
||
192 | * @return string |
||
193 | */ |
||
194 | protected function renderRegion(): string |
||
202 | |||
203 | /** |
||
204 | * @return string |
||
205 | */ |
||
206 | protected function renderLegend(): string |
||
214 | |||
215 | /** |
||
216 | * @return string |
||
217 | */ |
||
218 | protected function renderTooltip(): string |
||
226 | |||
227 | /** |
||
228 | * @return string |
||
229 | */ |
||
230 | protected function renderSubchart(): string |
||
238 | |||
239 | /** |
||
240 | * @return string |
||
241 | */ |
||
242 | protected function renderZoom(): string |
||
250 | |||
251 | /** |
||
252 | * @return string |
||
253 | */ |
||
254 | protected function renderPoint(): string |
||
262 | |||
263 | /** |
||
264 | * @return string |
||
265 | */ |
||
266 | protected function renderLine(): string |
||
274 | |||
275 | /** |
||
276 | * @return string |
||
277 | */ |
||
278 | protected function renderBar(): string |
||
286 | |||
287 | /** |
||
288 | * @return string |
||
289 | */ |
||
290 | protected function renderPie(): string |
||
298 | |||
299 | /** |
||
300 | * @return string |
||
301 | */ |
||
302 | protected function renderDonut(): string |
||
310 | |||
311 | /** |
||
312 | * @return string |
||
313 | */ |
||
314 | protected function renderGauge(): string |
||
322 | |||
323 | /** |
||
324 | * @return string |
||
325 | */ |
||
326 | protected function renderTitle(): string |
||
334 | } |
||
335 |