Complex classes like InputField 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 InputField, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
31 | class InputField |
||
32 | { |
||
33 | |||
34 | // input type constants |
||
35 | const INPUT_TEXT = 'textInput'; |
||
36 | const INPUT_STATIC = 'staticInput'; |
||
37 | const INPUT_READONLY = 'textInputReadOnly'; |
||
38 | const INPUT_TEXTAREA = 'textarea'; |
||
39 | |||
40 | const INPUT_PASSWORD = 'passwordInput'; |
||
41 | const INPUT_PASSWORD_STRENGTH = 'passwordStrength'; |
||
42 | |||
43 | const INPUT_DROPDOWN_LIST = 'dropDownList'; |
||
44 | const INPUT_LIST_BOX = 'listBox'; |
||
45 | const INPUT_SELECT2 = 'select2'; |
||
46 | const INPUT_SELECT2_MULTI = 'select2Multi'; |
||
47 | const INPUT_SELECT2_TAGS = 'select2Tags'; //wlchere todo |
||
48 | const INPUT_SELECT_PICKER = 'bsSelectPicker'; |
||
49 | const INPUT_SELECT_PICKER_MULTI = 'bsSelectPickerMulti'; |
||
50 | const INPUT_SELECT_SPLITTER = 'bsSelectSplitter'; |
||
51 | |||
52 | const INPUT_CHECKBOX = 'checkbox'; |
||
53 | const INPUT_CHECKBOX_BASIC = 'checkboxBasic'; |
||
54 | const INPUT_CHECKBOX_SWITCH = 'checkboxSwitch'; |
||
55 | const INPUT_CHECKBOX_ICHECK = 'checkboxIcheck'; |
||
56 | const INPUT_CHECKBOX_LIST = 'checkboxList'; |
||
57 | const INPUT_CHECKBOX_LIST_ICHECK = 'checkboxListIcheck'; |
||
58 | |||
59 | const INPUT_RADIO = 'radio'; |
||
60 | const INPUT_RADIO_LIST = 'radioList'; |
||
61 | const INPUT_RADIO_LIST_ICHECK = 'radioListIcheck'; |
||
62 | |||
63 | const INPUT_MULTISELECT = 'multiSelect'; |
||
64 | const INPUT_FILE = 'fileInput'; //wlchere todo |
||
65 | const INPUT_HTML5 = 'input'; //wlchere todo |
||
66 | const INPUT_WIDGET = 'widget'; //wlchere todo |
||
67 | const INPUT_HIDDEN = 'hidden'; //wlchere todo |
||
68 | const INPUT_COLOR = 'bsColorPicker'; |
||
69 | const INPUT_MINI_COLORS = 'miniColors'; |
||
70 | const INPUT_RAW = 'raw'; |
||
71 | |||
72 | const INPUT_INTEGER = 'textInputInteger'; |
||
73 | const INPUT_DECIMAL = 'textInputDecimal'; |
||
74 | const INPUT_DATE = 'datePicker'; |
||
75 | const INPUT_DATETIME = 'dateTimePicker'; |
||
76 | const INPUT_TIME = 'timePicker'; |
||
77 | const INPUT_YEAR = 'textInputYear'; |
||
78 | |||
79 | const INPUT_EDITOR_CK = 'editor_CK'; |
||
80 | const INPUT_EDITOR_BS_WYSIHTML5 = 'editor_BSW5'; //wlchere todo |
||
81 | const INPUT_EDITOR_BS_SUMMERNOTE = 'editor_BSSN'; //wlchere todo |
||
82 | |||
83 | // input size constants |
||
84 | const INPUT_SIZE_NONE = ''; |
||
85 | const INPUT_SIZE_AUTO = 'auto'; |
||
86 | const INPUT_SIZE_MINI = 'mini'; |
||
87 | const INPUT_SIZE_XSMALL = 'xsmall'; |
||
88 | const INPUT_SIZE_SMALL = 'small'; |
||
89 | const INPUT_SIZE_MEDIUM = 'medium'; |
||
90 | const INPUT_SIZE_LARGE = 'large'; |
||
91 | const INPUT_SIZE_XLARGE = 'xlarge'; |
||
92 | const INPUT_SIZE_MAX = 'max'; |
||
93 | |||
94 | // tooltip icon position |
||
95 | const ICON_POSITION_LEFT = 'left'; |
||
96 | const ICON_POSITION_RIGHT = 'right'; |
||
97 | |||
98 | /** |
||
99 | * Return default input field type based on column schema for attribute |
||
100 | * @param string $attributeName |
||
101 | * @param \yii\db\ColumnSchema $columnSchema |
||
102 | * @param array|null $config attributeConfig (active element) |
||
103 | * @return string |
||
104 | */ |
||
105 | public static function getDefaultInputFieldType($attributeName, $columnSchema, $config = null) |
||
188 | |||
189 | /** |
||
190 | * Get default widget class based on input field type |
||
191 | * @param string $type |
||
192 | * @return string |
||
193 | */ |
||
194 | public static function getWidgetClassNameFromFieldType($type) |
||
242 | |||
243 | /** |
||
244 | * Check if field input type supports icon prefix |
||
245 | * |
||
246 | * @param string $type |
||
247 | * @return boolean |
||
248 | */ |
||
249 | public static function getIsIconSupportedFieldType($type) |
||
270 | |||
271 | /** |
||
272 | * Return true if input field type is an editor area |
||
273 | * |
||
274 | * @param string $type |
||
275 | * @return boolean |
||
276 | */ |
||
277 | public static function getIsEditorFromFieldType($type) |
||
288 | |||
289 | /** |
||
290 | * Check if input type is a widget |
||
291 | * |
||
292 | * @param string $type |
||
293 | * @return boolean |
||
294 | */ |
||
295 | public static function getIsWidgetFromFieldType($type) |
||
303 | |||
304 | } |
||
305 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.