Complex classes like WidgetOptions 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 WidgetOptions, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
23 | class WidgetOptions extends AbstractOptions implements WidgetOptionsInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var string |
||
27 | * |
||
28 | * CSS class for the timeline. Provides the twitter one by default |
||
29 | */ |
||
30 | protected $class = 'twitter-timeline'; |
||
31 | /** |
||
32 | * @var string |
||
33 | * |
||
34 | * Timeline URL |
||
35 | */ |
||
36 | protected $href; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | * |
||
41 | * Text for the link that appears above the timeline |
||
42 | * ie: tweets from @mpalourdio |
||
43 | */ |
||
44 | protected $hrefText; |
||
45 | |||
46 | /** |
||
47 | * @var string |
||
48 | * |
||
49 | * Your widget ID |
||
50 | */ |
||
51 | protected $dataWidgetId; |
||
52 | /** |
||
53 | * @var string |
||
54 | * |
||
55 | * Set by adding a data-theme="dark" attribute to the embed code. |
||
56 | */ |
||
57 | protected $dataTheme; |
||
58 | /** |
||
59 | * @var string |
||
60 | * |
||
61 | * Theme: Set by adding a data-link-color="#cc0000" attribute. |
||
62 | * Note that some icons in the widget will also appear this color. |
||
63 | */ |
||
64 | protected $dataLinkColor; |
||
65 | |||
66 | /** |
||
67 | * @var int |
||
68 | * |
||
69 | * Set using the standard HTML width attribute on the embed code (units are pixels.) |
||
70 | */ |
||
71 | protected $width; |
||
72 | /** |
||
73 | * @var int |
||
74 | * |
||
75 | * Set using the standard HTML height attribute on the embed code (units are pixels.) |
||
76 | */ |
||
77 | protected $height; |
||
78 | /** |
||
79 | * @var string |
||
80 | * |
||
81 | * Control the widget layout and chrome |
||
82 | */ |
||
83 | protected $dataChrome; |
||
84 | /** |
||
85 | * @var string |
||
86 | * |
||
87 | * Change the border color used by the widget. Takes an #abc123 hex format color e.g. data-border-color="#cc0000" |
||
88 | */ |
||
89 | protected $dataBorderColor; |
||
90 | |||
91 | /** |
||
92 | * @var string |
||
93 | * |
||
94 | * The widget language is detected from the page, based on the HTML lang attribute of your content. |
||
95 | * You can also set the HTML lang attribute on the embed code itself. |
||
96 | */ |
||
97 | protected $language; |
||
98 | /** |
||
99 | * @var int |
||
100 | * |
||
101 | * To fix the size of a timeline to a preset number of Tweets, use the data-tweet-limit="5" attribute with any value |
||
102 | * between 1 and 20 Tweets. The timeline will render the specified number of Tweets from the timeline, expanding the |
||
103 | * height of the widget to display all Tweets without scrolling. Since the widget is of a fixed size, it will not |
||
104 | * poll for updates when using this option. |
||
105 | */ |
||
106 | protected $dataTweetLimit; |
||
107 | /** |
||
108 | * @var string |
||
109 | * |
||
110 | * As per the Tweet and follow buttons, you may provide a comma-separated list of user screen names as suggested |
||
111 | * followers to a user after they reply, Retweet, or favorite a Tweet in the timeline. Use a |
||
112 | * data-related="benward,endform" attribute on the embed code. |
||
113 | */ |
||
114 | protected $dataRelated; |
||
115 | /** |
||
116 | * @var string |
||
117 | * |
||
118 | * ARIA is an accessibility system that aids people using assistive technology interacting with dynamic web content. |
||
119 | * Read more about ARIA on W3C’s website. By default, the embedded timeline uses the least obtrusive |
||
120 | * setting: aria-polite="polite". If you’re using an embedded timeline as a primary source of content on your |
||
121 | * page, you may wish to override this to the assertive setting, using data-aria-polite="assertive". |
||
122 | */ |
||
123 | protected $dataAriaPolite; |
||
124 | |||
125 | /** |
||
126 | * @return string |
||
127 | */ |
||
128 | public function getDataChrome() |
||
132 | |||
133 | /** |
||
134 | * @param string $dataChrome |
||
135 | * @throws InvalidArgumentException |
||
136 | * @return self |
||
137 | */ |
||
138 | public function setDataChrome($dataChrome) |
||
148 | |||
149 | /** |
||
150 | * @return string |
||
151 | */ |
||
152 | public function getClass() |
||
156 | |||
157 | /** |
||
158 | * @param string $class |
||
159 | * @throws InvalidArgumentException |
||
160 | * @return self |
||
161 | */ |
||
162 | public function setClass($class) |
||
172 | |||
173 | /** |
||
174 | * @return string |
||
175 | */ |
||
176 | public function getDataAriaPolite() |
||
180 | |||
181 | /** |
||
182 | * @param string $dataAriaPolite |
||
183 | * @throws InvalidArgumentException |
||
184 | * @return self |
||
185 | */ |
||
186 | public function setDataAriaPolite($dataAriaPolite) |
||
196 | |||
197 | /** |
||
198 | * @return string |
||
199 | */ |
||
200 | public function getDataBorderColor() |
||
204 | |||
205 | /** |
||
206 | * @param string $dataBorderColor |
||
207 | * @throws InvalidArgumentException |
||
208 | * @return self |
||
209 | */ |
||
210 | public function setDataBorderColor($dataBorderColor) |
||
220 | |||
221 | /** |
||
222 | * @return string |
||
223 | */ |
||
224 | public function getDataLinkColor() |
||
228 | |||
229 | /** |
||
230 | * @param string $dataLinkColor |
||
231 | * @throws InvalidArgumentException |
||
232 | * @return self |
||
233 | */ |
||
234 | public function setDataLinkColor($dataLinkColor) |
||
244 | |||
245 | /** |
||
246 | * @return string |
||
247 | */ |
||
248 | public function getDataRelated() |
||
252 | |||
253 | /** |
||
254 | * @param string $dataRelated |
||
255 | * @throws InvalidArgumentException |
||
256 | * @return self |
||
257 | */ |
||
258 | public function setDataRelated($dataRelated) |
||
268 | |||
269 | /** |
||
270 | * @return string |
||
271 | */ |
||
272 | public function getDataTheme() |
||
276 | |||
277 | /** |
||
278 | * @param string $dataTheme |
||
279 | * @throws InvalidArgumentException |
||
280 | * @return self |
||
281 | */ |
||
282 | public function setDataTheme($dataTheme) |
||
292 | |||
293 | /** |
||
294 | * @return int |
||
295 | */ |
||
296 | public function getDataTweetLimit() |
||
300 | |||
301 | /** |
||
302 | * @param int $dataTweetLimit |
||
303 | * @throws InvalidArgumentException |
||
304 | * @return self |
||
305 | */ |
||
306 | public function setDataTweetLimit($dataTweetLimit) |
||
316 | |||
317 | /** |
||
318 | * @return string |
||
319 | */ |
||
320 | public function getDataWidgetId() |
||
324 | |||
325 | /** |
||
326 | * @param string $dataWidgetId |
||
327 | * @throws InvalidArgumentException |
||
328 | * @return self |
||
329 | * |
||
330 | * Note: long integers will be converted to float (32 bits). Give this setter a string |
||
331 | */ |
||
332 | public function setDataWidgetId($dataWidgetId) |
||
344 | |||
345 | /** |
||
346 | * @return int |
||
347 | */ |
||
348 | public function getHeight() |
||
352 | |||
353 | /** |
||
354 | * @param int $height |
||
355 | * @throws InvalidArgumentException |
||
356 | * @return self |
||
357 | */ |
||
358 | public function setHeight($height) |
||
368 | |||
369 | /** |
||
370 | * @return string |
||
371 | */ |
||
372 | public function getHref() |
||
376 | |||
377 | /** |
||
378 | * @param string $href |
||
379 | * @throws InvalidArgumentException |
||
380 | * @return self |
||
381 | */ |
||
382 | public function setHref($href) |
||
392 | |||
393 | /** |
||
394 | * @return string |
||
395 | */ |
||
396 | public function getHrefText() |
||
400 | |||
401 | /** |
||
402 | * @param string $hrefText |
||
403 | * @throws InvalidArgumentException |
||
404 | * @return self |
||
405 | */ |
||
406 | public function setHrefText($hrefText) |
||
416 | |||
417 | /** |
||
418 | * @return string |
||
419 | */ |
||
420 | public function getLanguage() |
||
424 | |||
425 | /** |
||
426 | * @param string $language |
||
427 | * @throws InvalidArgumentException |
||
428 | * @return self |
||
429 | */ |
||
430 | public function setLanguage($language) |
||
440 | |||
441 | /** |
||
442 | * @return int |
||
443 | */ |
||
444 | public function getWidth() |
||
448 | |||
449 | /** |
||
450 | * @param int $width |
||
451 | * @throws InvalidArgumentException |
||
452 | * @return self |
||
453 | */ |
||
454 | public function setWidth($width) |
||
464 | } |
||
465 |