| Conditions | 33 |
| Paths | > 20000 |
| Total Lines | 163 |
| 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; |
||
| 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 | if ( $classes ) { |
||
| 135 | $cstr = implode( " ", $classes ); |
||
| 136 | $extraatt .= " class=\"$cstr\""; |
||
| 137 | } |
||
| 138 | |||
| 139 | $inname = $input_name; |
||
| 140 | if ( $is_list ) { |
||
| 141 | $inname .= '[]'; |
||
| 142 | } |
||
| 143 | |||
| 144 | // TODO Use Html:: |
||
| 145 | |||
| 146 | $spanextra = $is_mandatory ? 'mandatoryFieldSpan' : ''; |
||
| 147 | $is_single_select = (!$is_list) ? 'select-sfs-single' : '' ; |
||
| 148 | $ret = "<span class=\"inputSpan select-sfs $is_single_select $spanextra\"><select name='$inname' id='input_$sfgFieldNum' $extraatt>"; |
||
| 149 | |||
| 150 | $curvalues = null; |
||
| 151 | if ( $cur_value ) { |
||
| 152 | if ( $cur_value === 'current user' ) { |
||
| 153 | $cur_value = $wgUser->getName(); |
||
| 154 | } |
||
| 155 | if ( is_array( $cur_value ) ) { |
||
| 156 | $curvalues = $cur_value; |
||
| 157 | } else { |
||
| 158 | // delimiter for $cur_value is always ',' - PF seems to ignore $wgPageFormsListSeparator |
||
| 159 | $curvalues = array_map( "trim", explode( $selectField->getDelimiter(), $cur_value ) ); |
||
| 160 | } |
||
| 161 | |||
| 162 | } else { |
||
| 163 | $curvalues = []; |
||
| 164 | } |
||
| 165 | |||
| 166 | |||
| 167 | $labelArray = []; |
||
| 168 | if ( array_key_exists( "label", $other_args ) && $curvalues ) { |
||
| 169 | // $labelArray = $this->getLabels( $curvalues ); |
||
| 170 | } |
||
| 171 | |||
| 172 | // TODO handle empty value case. |
||
| 173 | $ret .= "<option></option>"; |
||
| 174 | |||
| 175 | if ( $selectField->hasStaticValues() ) { |
||
| 176 | |||
| 177 | $values = $selectField->getValues(); |
||
| 178 | |||
| 179 | if ( array_key_exists( "label", $other_args ) && $values ) { |
||
| 180 | $labelArray = $this->getLabels( $values ); |
||
| 181 | } |
||
| 182 | |||
| 183 | if ( is_array( $values ) ) { |
||
| 184 | |||
| 185 | foreach ( $values as $val ) { |
||
| 186 | |||
| 187 | $selected = ""; |
||
| 188 | |||
| 189 | if ( array_key_exists( $val, $labelArray ) ) { |
||
| 190 | |||
| 191 | if ( in_array( $labelArray[ $val ][0], $curvalues ) ) { |
||
| 192 | $selected = " selected='selected'"; |
||
| 193 | } |
||
| 194 | |||
| 195 | $ret.="<option".$selected." value='".$labelArray[ $val ][0]."'>".$labelArray[ $val ][1]."</option>"; |
||
| 196 | |||
| 197 | } else { |
||
| 198 | |||
| 199 | if ( in_array( $val, $curvalues ) ) { |
||
| 200 | $selected = " selected='selected'"; |
||
| 201 | } |
||
| 202 | |||
| 203 | $ret .= "<option".$selected.">$val</option>"; |
||
| 204 | } |
||
| 205 | } |
||
| 206 | } |
||
| 207 | } else { |
||
| 208 | |||
| 209 | foreach ( $curvalues as $cur ) { |
||
| 210 | $selected = ""; |
||
| 211 | |||
| 212 | if ( array_key_exists( $cur, $labelArray ) ) { |
||
| 213 | |||
| 214 | if ( in_array( $labelArray[ $cur ][0], $curvalues ) ) { |
||
| 215 | $selected = " selected='selected'"; |
||
| 216 | } |
||
| 217 | |||
| 218 | $ret.="<option".$selected." value='".$labelArray[ $cur ][0]."'>".$labelArray[ $cur ][1]."</option>"; |
||
| 219 | |||
| 220 | } else { |
||
| 221 | if ( in_array( $cur, $curvalues ) ) { |
||
| 222 | $selected = " selected='selected'"; |
||
| 223 | } |
||
| 224 | $ret.="<option".$selected.">$cur</option>"; |
||
| 225 | } |
||
| 226 | } |
||
| 227 | |||
| 228 | } |
||
| 229 | |||
| 230 | $ret .= "</select></span>"; |
||
| 231 | $ret .= "<span id=\"info_$sfgFieldNum\" class=\"errorMessage\"></span>"; |
||
| 232 | |||
| 233 | if ( $other_args["is_list"] ) { |
||
| 234 | $hiddenname = $input_name . '[is_list]'; |
||
| 235 | $ret .= "<input type='hidden' name='$hiddenname' value='1' />"; |
||
| 236 | } |
||
| 237 | |||
| 238 | return $ret; |
||
| 239 | } |
||
| 240 | |||
| 308 |
This check marks private properties in classes that are never used. Those properties can be removed.