Complex classes like BootstrapBase 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 BootstrapBase, and based on these observations, apply Extract Interface, too.
1 | <?php namespace Cornford\Bootstrapper; |
||
9 | abstract class BootstrapBase { |
||
10 | |||
11 | const FORM_VERTICAL = 'vertical'; |
||
12 | const FORM_HORIZONTAL = 'horizontal'; |
||
13 | const FORM_INLINE = 'inline'; |
||
14 | |||
15 | const CSS_BOOTSTRAP_CDN = '//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.min.css'; |
||
16 | const CSS_BOOTSTRAP_LOCAL = 'packages/cornford/bootstrapper/assets/css/bootstrap.min.css'; |
||
17 | |||
18 | const JS_BOOTSTRAP_CDN = '//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/js/bootstrap.min.js'; |
||
19 | const JS_BOOTSTRAP_LOCAL = 'packages/cornford/bootstrapper/assets/js/bootstrap.min.js'; |
||
20 | |||
21 | const JS_JQUERY_CDN = '//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js'; |
||
22 | const JS_JQUERY_LOCAL = 'packages/cornford/bootstrapper/assets/js/jquery.min.js'; |
||
23 | |||
24 | const JS_MOMENT_CDN = '//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js'; |
||
25 | const JS_MOMENT_LOCAL = 'packages/cornford/bootstrapper/assets/js/moment.min.js'; |
||
26 | |||
27 | const CSS_DATETIME_CDN = '//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/3.1.3/css/bootstrap-datetimepicker.min.css'; |
||
28 | const CSS_DATETIME_LOCAL = 'packages/cornford/bootstrapper/assets/css/bootstrap-datetimepicker.min.css'; |
||
29 | |||
30 | const JS_DATETIME_CDN = '//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/3.1.3/js/bootstrap-datetimepicker.min.js'; |
||
31 | const JS_DATETIME_LOCAL = 'packages/cornford/bootstrapper/assets/js/bootstrap-datetimepicker.min.js'; |
||
32 | |||
33 | /** |
||
34 | * Form |
||
35 | * |
||
36 | * @var \Illuminate\Html\FormBuilder |
||
37 | */ |
||
38 | protected $form; |
||
39 | |||
40 | /** |
||
41 | * HTML |
||
42 | * |
||
43 | * @var \Illuminate\Html\HtmlBuilder |
||
44 | */ |
||
45 | protected $html; |
||
46 | |||
47 | /** |
||
48 | * Input |
||
49 | * |
||
50 | * @var \Illuminate\Http\Request |
||
51 | */ |
||
52 | protected $input; |
||
53 | |||
54 | /** |
||
55 | * Form Type |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $formType = self::FORM_VERTICAL; |
||
60 | |||
61 | /** |
||
62 | * Form Input Class |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | protected $inputClass; |
||
67 | |||
68 | /** |
||
69 | * Form Label Class |
||
70 | * |
||
71 | * @var string |
||
72 | */ |
||
73 | protected $labelClass; |
||
74 | |||
75 | public function __construct(FormBuilder $form, HtmlBuilder $html, Request $input) |
||
81 | |||
82 | /** |
||
83 | * Set the form type |
||
84 | * |
||
85 | * @param string $type |
||
86 | * @param string $inputClass |
||
87 | * @param string $labelClass |
||
88 | * |
||
89 | * @return void |
||
90 | */ |
||
91 | protected function form($type = self::FORM_VERTICAL, $inputClass = '', $labelClass = '') { |
||
96 | |||
97 | /** |
||
98 | * Set the form type to vertical |
||
99 | * |
||
100 | * @return self |
||
101 | */ |
||
102 | public function vertical() { |
||
107 | |||
108 | /** |
||
109 | * Set the form type to horizontal |
||
110 | * |
||
111 | * @param string $inputClass |
||
112 | * @param string $labelClass |
||
113 | * |
||
114 | * @return self |
||
115 | */ |
||
116 | public function horizontal($inputClass = '', $labelClass = '') { |
||
121 | |||
122 | /** |
||
123 | * Set the form type to inline |
||
124 | * |
||
125 | * @param string $labelClass |
||
126 | * |
||
127 | * @return self |
||
128 | */ |
||
129 | public function inline($labelClass = '') { |
||
134 | |||
135 | /** |
||
136 | * Get the form type |
||
137 | * |
||
138 | * @return string |
||
139 | */ |
||
140 | public function getFormType() { |
||
143 | |||
144 | /** |
||
145 | * Include the Bootstrap file |
||
146 | * |
||
147 | * @param string $type |
||
148 | * @param string $location |
||
149 | * @param array $attributes |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | protected function add($type, $location, array $attributes = array()) |
||
157 | |||
158 | /** |
||
159 | * Create a form label field. |
||
160 | * |
||
161 | * @param string $name |
||
162 | * @param string $label |
||
163 | * @param array $options |
||
164 | * @param string $content |
||
165 | * |
||
166 | * @return string |
||
167 | */ |
||
168 | protected function label($name, $label = null, array $options = array(), $content = null) { |
||
178 | |||
179 | /** |
||
180 | * Create a form error helper field. |
||
181 | * |
||
182 | * @param string $name |
||
183 | * @param \Illuminate\Support\MessageBag $errors |
||
184 | * @param string $wrap |
||
185 | * |
||
186 | * @return string |
||
187 | */ |
||
188 | protected function errors($name, $errors = null, $wrap = '<span class="help-block">:message</span>') { |
||
197 | |||
198 | /** |
||
199 | * Create a form group element. |
||
200 | * |
||
201 | * @param string $name |
||
202 | * @param \Illuminate\Support\MessageBag $errors |
||
203 | * @param string $class |
||
204 | * @param array $options |
||
205 | * |
||
206 | * @return string |
||
207 | */ |
||
208 | protected function group($name, $errors = null, $class = 'form-group', array $options = array()) |
||
216 | |||
217 | /** |
||
218 | * Create a form input field. |
||
219 | * |
||
220 | * @param string $type |
||
221 | * @param string $name |
||
222 | * @param string $value |
||
223 | * @param string $label |
||
224 | * @param \Illuminate\Support\MessageBag $errors |
||
225 | * @param array $options |
||
226 | * @param array $parameters |
||
227 | * |
||
228 | * @return string |
||
229 | */ |
||
230 | protected function input($type = 'text', $name, $label = null, $value = null, $errors = null, array $options = array(), array $parameters = array()) |
||
329 | |||
330 | /** |
||
331 | * Create a form select field. |
||
332 | * |
||
333 | * @param string $name |
||
334 | * @param string $label |
||
335 | * @param array $list |
||
336 | * @param string $selected |
||
337 | * @param \Illuminate\Support\MessageBag $errors |
||
338 | * @param array $options |
||
339 | * |
||
340 | * @return string |
||
341 | */ |
||
342 | protected function options($name, $label = null, array $list = array(), $selected = null, $errors = null, array $options = array()) |
||
372 | |||
373 | /** |
||
374 | * Create a form field. |
||
375 | * |
||
376 | * @param string $type |
||
377 | * @param string $name |
||
378 | * @param string $label |
||
379 | * @param string $value |
||
380 | * @param string $checked |
||
381 | * @param array $options |
||
382 | * |
||
383 | * @return string |
||
384 | */ |
||
385 | protected function field($type, $name, $label = null, $value = null, $checked = null, array $options = array()) |
||
414 | |||
415 | /** |
||
416 | * Create a form action button. |
||
417 | * |
||
418 | * @param string $value |
||
419 | * @param string $type |
||
420 | * @param array $attributes |
||
421 | * |
||
422 | * @return string |
||
423 | */ |
||
424 | protected function action($type, $value, array $attributes = array()) |
||
459 | |||
460 | /** |
||
461 | * Create a button link. |
||
462 | * |
||
463 | * @param string $type |
||
464 | * @param string $location |
||
465 | * @param string $title |
||
466 | * @param array $parameters |
||
467 | * @param string $secure |
||
468 | * @param array $attributes |
||
469 | * |
||
470 | * @return string |
||
471 | */ |
||
472 | protected function hyperlink($type, $location, $title = null, array $parameters = array(), array $attributes = array(), $secure = null) |
||
492 | |||
493 | /** |
||
494 | * Create an alert item with optional emphasis. |
||
495 | * |
||
496 | * @param string $type |
||
497 | * @param string $content |
||
498 | * @param string $emphasis |
||
499 | * @param boolean $dismissible |
||
500 | * @param array $attributes |
||
501 | * |
||
502 | * @return string |
||
503 | */ |
||
504 | protected function alert($type = 'message', $content = null, $emphasis = null, $dismissible = false, array $attributes = array()) |
||
517 | |||
518 | /** |
||
519 | * Get container attributes. |
||
520 | * |
||
521 | * @param array &$attributes |
||
522 | * |
||
523 | * @return array |
||
524 | */ |
||
525 | protected function getContainerAttributes(array &$attributes = array()) |
||
536 | |||
537 | /** |
||
538 | * Get label attributes. |
||
539 | * |
||
540 | * @param array &$attributes |
||
541 | * |
||
542 | * @return array |
||
543 | */ |
||
544 | protected function getLabelAttributes(array &$attributes = array()) |
||
555 | |||
556 | } |
||
557 |