| Conditions | 31 |
| Paths | > 20000 |
| Total Lines | 266 |
| Code Lines | 208 |
| Lines | 21 |
| Ratio | 7.89 % |
| 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 |
||
| 42 | function execute() { |
||
| 43 | ?> |
||
| 44 | <div class="mw-ui-container"> |
||
| 45 | <?php if ( $this->haveData( 'languages' ) ) { ?> |
||
| 46 | <div id="languagelinks"> |
||
| 47 | <p><?php $this->html( 'languages' ); ?></p> |
||
| 48 | </div> |
||
| 49 | <?php } |
||
| 50 | if ( !wfMessage( 'signupstart' )->isDisabled() ) { ?> |
||
| 51 | <div id="signupstart"><?php $this->msgWiki( 'signupstart' ); ?></div> |
||
| 52 | <?php } ?> |
||
| 53 | <div id="userloginForm"> |
||
| 54 | <form name="userlogin2" id="userlogin2" class="mw-ui-vform" method="post" action="<?php $this->text( 'action' ); ?>"> |
||
| 55 | <section class="mw-form-header"> |
||
| 56 | <?php $this->html( 'header' ); ?> |
||
| 57 | </section> |
||
| 58 | <!-- This element is used by the mediawiki.special.userlogin.signup.js module. --> |
||
| 59 | <div |
||
| 60 | id="mw-createacct-status-area" |
||
| 61 | <?php if ( $this->data['message'] ) { ?> |
||
| 62 | class="<?php echo $this->data['messagetype']; ?>box" |
||
| 63 | <?php } else { ?> |
||
| 64 | style="display: none;" |
||
| 65 | <?php } ?> |
||
| 66 | > |
||
| 67 | View Code Duplication | <?php if ( $this->data['message'] ) { ?> |
|
| 68 | <?php if ( $this->data['messagetype'] == 'error' ) { ?> |
||
| 69 | <strong><?php $this->msg( 'createacct-error' ); ?></strong> |
||
| 70 | <br /> |
||
| 71 | <?php } ?> |
||
| 72 | <?php $this->html( 'message' ); ?> |
||
| 73 | <?php } ?> |
||
| 74 | </div> |
||
| 75 | |||
| 76 | <?php if ( $this->data['formheader'] ) { ?> |
||
| 77 | <div class="mw-form-formheader"> |
||
| 78 | <?php $this->html( 'formheader' ); /* extensions such as MobileFrontend add html here */ ?> |
||
| 79 | </div> |
||
| 80 | <?php } ?> |
||
| 81 | |||
| 82 | <div class="mw-ui-vform-field"> |
||
| 83 | <label for='wpName2'> |
||
| 84 | <?php $this->msg( 'userlogin-yourname' ); ?> |
||
| 85 | |||
| 86 | <span class="mw-ui-flush-right"><?php echo $this->getMsg( 'createacct-helpusername' )->parse(); ?></span> |
||
| 87 | </label> |
||
| 88 | <?php |
||
| 89 | echo Html::input( 'wpName', $this->data['name'], 'text', [ |
||
| 90 | 'class' => 'mw-ui-input loginText', |
||
| 91 | 'id' => 'wpName2', |
||
| 92 | 'tabindex' => '1', |
||
| 93 | 'size' => '20', |
||
| 94 | 'required', |
||
| 95 | 'placeholder' => $this->getMsg( $this->data['loggedin'] ? |
||
| 96 | 'createacct-another-username-ph' : 'userlogin-yourname-ph' )->text(), |
||
| 97 | ] ); |
||
| 98 | ?> |
||
| 99 | </div> |
||
| 100 | |||
| 101 | <div class="mw-ui-vform-field"> |
||
| 102 | <?php if ( $this->data['createemail'] ) { ?> |
||
| 103 | <div class="mw-ui-checkbox"> |
||
| 104 | <input name="wpCreateaccountMail" type="checkbox" value="1" id="wpCreateaccountMail" tabindex="2" |
||
| 105 | <?php if ( $this->data['createemailset'] ) { |
||
| 106 | echo 'checked="checked"'; |
||
| 107 | } ?> |
||
| 108 | ><label for="wpCreateaccountMail"> |
||
| 109 | <?php $this->msg( 'createaccountmail' ); ?> |
||
| 110 | </label> |
||
| 111 | </div> |
||
| 112 | <?php } ?> |
||
| 113 | </div> |
||
| 114 | |||
| 115 | <div class="mw-ui-vform-field mw-row-password"> |
||
| 116 | <label for='wpPassword2'><?php $this->msg( 'userlogin-yourpassword' ); ?></label> |
||
| 117 | <?php |
||
| 118 | echo Html::input( 'wpPassword', null, 'password', [ |
||
| 119 | 'class' => 'mw-ui-input loginPassword', |
||
| 120 | 'id' => 'wpPassword2', |
||
| 121 | 'tabindex' => '3', |
||
| 122 | 'size' => '20', |
||
| 123 | 'required', |
||
| 124 | 'placeholder' => $this->getMsg( 'createacct-yourpassword-ph' )->text() |
||
| 125 | ] + User::passwordChangeInputAttribs() ); |
||
| 126 | ?> |
||
| 127 | </div> |
||
| 128 | |||
| 129 | <?php |
||
| 130 | View Code Duplication | if ( $this->data['usedomain'] ) { |
|
| 131 | $select = new XmlSelect( 'wpDomain', false, $this->data['domain'] ); |
||
| 132 | $select->setAttribute( 'tabindex', 4 ); |
||
| 133 | foreach ( $this->data['domainnames'] as $dom ) { |
||
| 134 | $select->addOption( $dom ); |
||
| 135 | } |
||
| 136 | ?> |
||
| 137 | <div class="mw-ui-vform-field" id="mw-user-domain-section"> |
||
| 138 | <label for="wpDomain"><?php $this->msg( 'yourdomainname' ); ?></label> |
||
| 139 | <div> |
||
| 140 | <?php echo $select->getHTML(); ?> |
||
| 141 | </div> |
||
| 142 | </div> |
||
| 143 | <?php } ?> |
||
| 144 | |||
| 145 | <div class="mw-ui-vform-field mw-row-password"> |
||
| 146 | <label for='wpRetype'><?php $this->msg( 'createacct-yourpasswordagain' ); ?></label> |
||
| 147 | <?php |
||
| 148 | echo Html::input( 'wpRetype', null, 'password', [ |
||
| 149 | 'class' => 'mw-ui-input loginPassword', |
||
| 150 | 'id' => 'wpRetype', |
||
| 151 | 'tabindex' => '5', |
||
| 152 | 'size' => '20', |
||
| 153 | 'required', |
||
| 154 | 'placeholder' => $this->getMsg( 'createacct-yourpasswordagain-ph' )->text() |
||
| 155 | ] + User::passwordChangeInputAttribs() ); |
||
| 156 | ?> |
||
| 157 | </div> |
||
| 158 | |||
| 159 | <div class="mw-ui-vform-field"> |
||
| 160 | <?php if ( $this->data['useemail'] ) { ?> |
||
| 161 | <label for='wpEmail'> |
||
| 162 | <?php |
||
| 163 | $this->msg( $this->data['emailrequired'] ? |
||
| 164 | 'createacct-emailrequired' : |
||
| 165 | 'createacct-emailoptional' |
||
| 166 | ); |
||
| 167 | ?> |
||
| 168 | </label> |
||
| 169 | <?php |
||
| 170 | echo Html::input( 'wpEmail', $this->data['email'], 'email', [ |
||
| 171 | 'class' => 'mw-ui-input loginText', |
||
| 172 | 'id' => 'wpEmail', |
||
| 173 | 'tabindex' => '6', |
||
| 174 | 'size' => '20', |
||
| 175 | 'required' => $this->data['emailrequired'], |
||
| 176 | 'placeholder' => $this->getMsg( $this->data['loggedin'] ? |
||
| 177 | 'createacct-another-email-ph' : 'createacct-email-ph' )->text() |
||
| 178 | ] ); |
||
| 179 | ?> |
||
| 180 | <?php } ?> |
||
| 181 | </div> |
||
| 182 | |||
| 183 | <?php if ( $this->data['userealname'] ) { ?> |
||
| 184 | <div class="mw-ui-vform-field"> |
||
| 185 | <label for='wpRealName'><?php $this->msg( 'createacct-realname' ); ?></label> |
||
| 186 | <input type='text' class='mw-ui-input loginText' name="wpRealName" id="wpRealName" |
||
| 187 | tabindex="7" |
||
| 188 | value="<?php $this->text( 'realname' ); ?>" size='20' /> |
||
| 189 | <div class="prefsectiontip"> |
||
| 190 | <?php $this->msgWiki( $this->data['loggedin'] ? 'createacct-another-realname-tip' : 'prefs-help-realname' ); ?> |
||
| 191 | </div> |
||
| 192 | </div> |
||
| 193 | <?php } ?> |
||
| 194 | |||
| 195 | <?php if ( $this->data['usereason'] ) { ?> |
||
| 196 | <div class="mw-ui-vform-field"> |
||
| 197 | <label for='wpReason'><?php $this->msg( 'createacct-reason' ); ?></label> |
||
| 198 | <?php echo Html::input( 'wpReason', $this->data['reason'], 'text', [ |
||
| 199 | 'class' => 'mw-ui-input loginText', |
||
| 200 | 'id' => 'wpReason', |
||
| 201 | 'tabindex' => '8', |
||
| 202 | 'size' => '20', |
||
| 203 | 'placeholder' => $this->getMsg( 'createacct-reason-ph' )->text() |
||
| 204 | ] ); ?> |
||
| 205 | </div> |
||
| 206 | <?php } ?> |
||
| 207 | |||
| 208 | <?php |
||
| 209 | $tabIndex = 9; |
||
| 210 | if ( isset( $this->data['extraInput'] ) && is_array( $this->data['extraInput'] ) ) { |
||
| 211 | foreach ( $this->data['extraInput'] as $inputItem ) { ?> |
||
| 212 | <div class="mw-ui-vform-field"> |
||
| 213 | <?php |
||
| 214 | // If it's a checkbox, output the whole thing (assume it has a msg). |
||
| 215 | if ( $inputItem['type'] == 'checkbox' ) { |
||
| 216 | ?> |
||
| 217 | <div class="mw-ui-checkbox"> |
||
| 218 | <input |
||
| 219 | name="<?php echo htmlspecialchars( $inputItem['name'] ); ?>" |
||
| 220 | id="<?php echo htmlspecialchars( $inputItem['name'] ); ?>" |
||
| 221 | type="checkbox" value="1" |
||
| 222 | tabindex="<?php echo $tabIndex++; ?>" |
||
| 223 | <?php if ( !empty( $inputItem['value'] ) ) { |
||
| 224 | echo 'checked="checked"'; |
||
| 225 | } ?> |
||
| 226 | ><label for="<?php echo htmlspecialchars( $inputItem['name'] ); ?>"> |
||
| 227 | <?php $this->msg( $inputItem['msg'] ); ?> |
||
| 228 | </label> |
||
| 229 | </div> |
||
| 230 | <?php |
||
| 231 | } else { |
||
| 232 | // Not a checkbox. |
||
| 233 | // TODO (bug 31909) support other input types, e.g. select boxes. |
||
| 234 | ?> |
||
| 235 | <?php if ( !empty( $inputItem['msg'] ) ) { ?> |
||
| 236 | <label for="<?php echo htmlspecialchars( $inputItem['name'] ); ?>"> |
||
| 237 | <?php $this->msgWiki( $inputItem['msg'] ); ?> |
||
| 238 | </label> |
||
| 239 | <?php } ?> |
||
| 240 | <input |
||
| 241 | type="<?php echo htmlspecialchars( $inputItem['type'] ); ?>" |
||
| 242 | class="mw-ui-input" |
||
| 243 | name="<?php echo htmlspecialchars( $inputItem['name'] ); ?>" |
||
| 244 | tabindex="<?php echo $tabIndex++; ?>" |
||
| 245 | value="<?php echo htmlspecialchars( $inputItem['value'] ); ?>" |
||
| 246 | id="<?php echo htmlspecialchars( $inputItem['name'] ); ?>" |
||
| 247 | /> |
||
| 248 | <?php } ?> |
||
| 249 | <?php if ( $inputItem['helptext'] !== false ) { ?> |
||
| 250 | <div class="prefsectiontip"> |
||
| 251 | <?php $this->msgWiki( $inputItem['helptext'] ); ?> |
||
| 252 | </div> |
||
| 253 | <?php } ?> |
||
| 254 | </div> |
||
| 255 | <?php |
||
| 256 | } |
||
| 257 | } |
||
| 258 | |||
| 259 | // A separate placeholder for any inserting any extrafields, e.g used by ConfirmEdit extension |
||
| 260 | if ( $this->haveData( 'extrafields' ) ) { |
||
| 261 | echo $this->data['extrafields']; |
||
| 262 | } |
||
| 263 | // skip one index. |
||
| 264 | $tabIndex++; |
||
| 265 | ?> |
||
| 266 | <div class="mw-ui-vform-field mw-submit"> |
||
| 267 | <?php |
||
| 268 | echo Html::submitButton( |
||
| 269 | $this->getMsg( $this->data['loggedin'] ? 'createacct-another-submit' : 'createacct-submit' ), |
||
| 270 | [ |
||
| 271 | 'id' => 'wpCreateaccount', |
||
| 272 | 'name' => 'wpCreateaccount', |
||
| 273 | 'tabindex' => $tabIndex++ |
||
| 274 | ], |
||
| 275 | [ |
||
| 276 | 'mw-ui-block', |
||
| 277 | 'mw-ui-constructive', |
||
| 278 | ] |
||
| 279 | ); |
||
| 280 | ?> |
||
| 281 | </div> |
||
| 282 | <?php if ( $this->haveData( 'uselang' ) ) { ?><input type="hidden" name="uselang" value="<?php $this->text( 'uselang' ); ?>" /><?php } ?> |
||
| 283 | <?php if ( $this->haveData( 'token' ) ) { ?><input type="hidden" name="wpCreateaccountToken" value="<?php $this->text( 'token' ); ?>" /><?php } ?> |
||
| 284 | </form> |
||
| 285 | <?php if ( !wfMessage( 'signupend' )->isDisabled() ) { ?> |
||
| 286 | <div id="signupend"><?php $this->html( 'signupend' ); ?></div> |
||
| 287 | <?php } ?> |
||
| 288 | </div> |
||
| 289 | <div class="mw-createacct-benefits-container"> |
||
| 290 | <h2><?php $this->msg( 'createacct-benefit-heading' ); ?></h2> |
||
| 291 | <div class="mw-createacct-benefits-list"> |
||
| 292 | <?php |
||
| 293 | for ( $benefitIdx = 1; $benefitIdx <= $this->data['benefitCount']; $benefitIdx++ ) { |
||
| 294 | // Pass each benefit's head text (by default a number) as a parameter to the body's message for PLURAL handling. |
||
| 295 | $headUnescaped = $this->getMsg( "createacct-benefit-head$benefitIdx" )->text(); |
||
| 296 | ?> |
||
| 297 | <div class="mw-number-text <?php $this->msg( "createacct-benefit-icon$benefitIdx" ); ?>"> |
||
| 298 | <h3><?php $this->msg( "createacct-benefit-head$benefitIdx" ); ?></h3> |
||
| 299 | <p><?php echo $this->getMsg( "createacct-benefit-body$benefitIdx" )->params( $headUnescaped )->escaped(); ?></p> |
||
| 300 | </div> |
||
| 301 | <?php } ?> |
||
| 302 | </div> |
||
| 303 | </div> |
||
| 304 | </div> |
||
| 305 | <?php |
||
| 306 | |||
| 307 | } |
||
| 308 | } |
||
| 309 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: