Conditions | 37 |
Paths | > 20000 |
Total Lines | 175 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
77 | public function getHTML( $cur_value = "", $input_name = "", $is_mandatory, $is_disabled, Array $other_args ) { |
||
78 | global $sfgFieldNum, $wgUser, $wgPageFormsShowOnSelect, $wgPageFormsFieldNum; |
||
79 | |||
80 | // shortcut to the SelectField object |
||
81 | $selectField = $this->mSelectField; |
||
82 | |||
83 | // get 'delimiter' before 'query' or 'function' |
||
84 | $selectField->setDelimiter( $other_args ); |
||
85 | |||
86 | if ( array_key_exists( "query", $other_args ) ) { |
||
87 | $selectField->setQuery( $other_args ); |
||
88 | } elseif ( array_key_exists( "function", $other_args ) ) { |
||
89 | $selectField->setFunction( $other_args ); |
||
90 | } |
||
91 | |||
92 | if ( array_key_exists( "label", $other_args ) ) { |
||
93 | $selectField->setLabel( $other_args ); |
||
94 | } |
||
95 | |||
96 | // parameters are only required if values needs to be retrieved dynamically |
||
97 | if ( !$selectField->hasStaticValues() ) { |
||
98 | $selectField->setSelectIsMultiple( $other_args ); |
||
99 | $selectField->setSelectTemplate( $input_name ); |
||
100 | $selectField->setSelectField( $input_name ); |
||
101 | $selectField->setValueTemplate( $other_args ); |
||
102 | $selectField->setValueField( $other_args ); |
||
103 | $selectField->setSelectRemove( $other_args ); |
||
104 | |||
105 | $item = Output::addToHeadItem( $selectField->getData() ); |
||
106 | } |
||
107 | |||
108 | Output::commitToParserOutput(); |
||
109 | |||
110 | // prepare the html input tag |
||
111 | |||
112 | $extraatt = ""; |
||
113 | $is_list = false; |
||
114 | |||
115 | if ( array_key_exists( 'is_list', $other_args ) && $other_args['is_list'] == true ) { |
||
116 | $is_list = true; |
||
117 | } |
||
118 | |||
119 | if ( $is_list ) { |
||
120 | $extraatt = ' multiple="multiple" '; |
||
121 | } |
||
122 | |||
123 | if ( array_key_exists( "size", $other_args ) ) { |
||
124 | $extraatt .= " size=\"{$other_args['size']}\""; |
||
125 | } |
||
126 | |||
127 | $classes = []; |
||
128 | if ( $is_mandatory ) { |
||
129 | $classes[] = "mandatoryField"; |
||
130 | } |
||
131 | if ( array_key_exists( "class", $other_args ) ) { |
||
132 | $classes[] = $other_args['class']; |
||
133 | } |
||
134 | $sfgFieldNum = $sfgFieldNum ? $sfgFieldNum : $wgPageFormsFieldNum; |
||
135 | $input_id = "input_$sfgFieldNum"; |
||
136 | if ( array_key_exists( 'show on select', $other_args ) ) { |
||
137 | $classes[] = 'pfShowIfSelected'; |
||
138 | foreach ( $other_args['show on select'] as $div_id => $options ) { |
||
139 | if ( array_key_exists( $input_id, $wgPageFormsShowOnSelect ) ) { |
||
140 | $wgPageFormsShowOnSelect[$input_id][] = array( $options, $div_id ); |
||
141 | } else { |
||
142 | $wgPageFormsShowOnSelect[$input_id] = array( array( $options, $div_id ) ); |
||
143 | } |
||
144 | } |
||
145 | } |
||
146 | if ( $classes ) { |
||
147 | $cstr = implode( " ", $classes ); |
||
148 | $extraatt .= " class=\"$cstr\""; |
||
149 | } |
||
150 | |||
151 | $inname = $input_name; |
||
152 | if ( $is_list ) { |
||
153 | $inname .= '[]'; |
||
154 | } |
||
155 | |||
156 | // TODO Use Html:: |
||
157 | |||
158 | $spanextra = $is_mandatory ? 'mandatoryFieldSpan' : ''; |
||
159 | $is_single_select = (!$is_list) ? 'select-sfs-single' : '' ; |
||
160 | $ret = "<span class=\"inputSpan select-sfs $is_single_select $spanextra\"><select name='$inname' id='input_$sfgFieldNum' $extraatt>"; |
||
161 | |||
162 | $curvalues = null; |
||
163 | if ( $cur_value ) { |
||
164 | if ( $cur_value === 'current user' ) { |
||
165 | $cur_value = $wgUser->getName(); |
||
166 | } |
||
167 | if ( is_array( $cur_value ) ) { |
||
168 | $curvalues = $cur_value; |
||
169 | } else { |
||
170 | // delimiter for $cur_value is always ',' - PF seems to ignore $wgPageFormsListSeparator |
||
171 | $curvalues = array_map( "trim", explode( $selectField->getDelimiter(), $cur_value ) ); |
||
172 | } |
||
173 | |||
174 | } else { |
||
175 | $curvalues = []; |
||
176 | } |
||
177 | |||
178 | |||
179 | $labelArray = []; |
||
180 | if ( array_key_exists( "label", $other_args ) && $curvalues ) { |
||
181 | // $labelArray = $this->getLabels( $curvalues ); |
||
182 | } |
||
183 | |||
184 | // TODO handle empty value case. |
||
185 | $ret .= "<option></option>"; |
||
186 | |||
187 | if ( $selectField->hasStaticValues() ) { |
||
188 | |||
189 | $values = $selectField->getValues(); |
||
190 | |||
191 | if ( array_key_exists( "label", $other_args ) && $values ) { |
||
192 | $labelArray = $this->getLabels( $values ); |
||
193 | } |
||
194 | |||
195 | if ( is_array( $values ) ) { |
||
196 | |||
197 | foreach ( $values as $val ) { |
||
198 | |||
199 | $selected = ""; |
||
200 | |||
201 | if ( array_key_exists( $val, $labelArray ) ) { |
||
202 | |||
203 | if ( in_array( $labelArray[ $val ][0], $curvalues ) ) { |
||
204 | $selected = " selected='selected'"; |
||
205 | } |
||
206 | |||
207 | $ret.="<option".$selected." value='".$labelArray[ $val ][0]."'>".$labelArray[ $val ][1]."</option>"; |
||
208 | |||
209 | } else { |
||
210 | |||
211 | if ( in_array( $val, $curvalues ) ) { |
||
212 | $selected = " selected='selected'"; |
||
213 | } |
||
214 | |||
215 | $ret .= "<option".$selected.">$val</option>"; |
||
216 | } |
||
217 | } |
||
218 | } |
||
219 | } else { |
||
220 | |||
221 | foreach ( $curvalues as $cur ) { |
||
222 | $selected = ""; |
||
223 | |||
224 | if ( array_key_exists( $cur, $labelArray ) ) { |
||
225 | |||
226 | if ( in_array( $labelArray[ $cur ][0], $curvalues ) ) { |
||
227 | $selected = " selected='selected'"; |
||
228 | } |
||
229 | |||
230 | $ret.="<option".$selected." value='".$labelArray[ $cur ][0]."'>".$labelArray[ $cur ][1]."</option>"; |
||
231 | |||
232 | } else { |
||
233 | if ( in_array( $cur, $curvalues ) ) { |
||
234 | $selected = " selected='selected'"; |
||
235 | } |
||
236 | $ret.="<option".$selected.">$cur</option>"; |
||
237 | } |
||
238 | } |
||
239 | |||
240 | } |
||
241 | |||
242 | $ret .= "</select></span>"; |
||
243 | $ret .= "<span id=\"info_$sfgFieldNum\" class=\"errorMessage\"></span>"; |
||
244 | |||
245 | if ( $other_args["is_list"] ) { |
||
246 | $hiddenname = $input_name . '[is_list]'; |
||
247 | $ret .= "<input type='hidden' name='$hiddenname' value='1' />"; |
||
248 | } |
||
249 | |||
250 | return $ret; |
||
251 | } |
||
252 | |||
320 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.