| Conditions | 20 |
| Paths | > 20000 |
| Total Lines | 257 |
| Code Lines | 173 |
| 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 |
||
| 396 | protected function getForm() { |
||
| 397 | $this->opts['title'] = $this->getPageTitle()->getPrefixedText(); |
||
| 398 | if ( !isset( $this->opts['target'] ) ) { |
||
| 399 | $this->opts['target'] = ''; |
||
| 400 | } else { |
||
| 401 | $this->opts['target'] = str_replace( '_', ' ', $this->opts['target'] ); |
||
| 402 | } |
||
| 403 | |||
| 404 | if ( !isset( $this->opts['namespace'] ) ) { |
||
| 405 | $this->opts['namespace'] = ''; |
||
| 406 | } |
||
| 407 | |||
| 408 | if ( !isset( $this->opts['nsInvert'] ) ) { |
||
| 409 | $this->opts['nsInvert'] = ''; |
||
| 410 | } |
||
| 411 | |||
| 412 | if ( !isset( $this->opts['associated'] ) ) { |
||
| 413 | $this->opts['associated'] = false; |
||
| 414 | } |
||
| 415 | |||
| 416 | if ( !isset( $this->opts['contribs'] ) ) { |
||
| 417 | $this->opts['contribs'] = 'user'; |
||
| 418 | } |
||
| 419 | |||
| 420 | if ( !isset( $this->opts['year'] ) ) { |
||
| 421 | $this->opts['year'] = ''; |
||
| 422 | } |
||
| 423 | |||
| 424 | if ( !isset( $this->opts['month'] ) ) { |
||
| 425 | $this->opts['month'] = ''; |
||
| 426 | } |
||
| 427 | |||
| 428 | if ( $this->opts['contribs'] == 'newbie' ) { |
||
| 429 | $this->opts['target'] = ''; |
||
| 430 | } |
||
| 431 | |||
| 432 | if ( !isset( $this->opts['tagfilter'] ) ) { |
||
| 433 | $this->opts['tagfilter'] = ''; |
||
| 434 | } |
||
| 435 | |||
| 436 | if ( !isset( $this->opts['topOnly'] ) ) { |
||
| 437 | $this->opts['topOnly'] = false; |
||
| 438 | } |
||
| 439 | |||
| 440 | if ( !isset( $this->opts['newOnly'] ) ) { |
||
| 441 | $this->opts['newOnly'] = false; |
||
| 442 | } |
||
| 443 | |||
| 444 | $form = Html::openElement( |
||
| 445 | 'form', |
||
| 446 | [ |
||
| 447 | 'method' => 'get', |
||
| 448 | 'action' => wfScript(), |
||
| 449 | 'class' => 'mw-contributions-form' |
||
| 450 | ] |
||
| 451 | ); |
||
| 452 | |||
| 453 | # Add hidden params for tracking except for parameters in $skipParameters |
||
| 454 | $skipParameters = [ |
||
| 455 | 'namespace', |
||
| 456 | 'nsInvert', |
||
| 457 | 'deletedOnly', |
||
| 458 | 'target', |
||
| 459 | 'contribs', |
||
| 460 | 'year', |
||
| 461 | 'month', |
||
| 462 | 'topOnly', |
||
| 463 | 'newOnly', |
||
| 464 | 'associated', |
||
| 465 | 'tagfilter' |
||
| 466 | ]; |
||
| 467 | |||
| 468 | foreach ( $this->opts as $name => $value ) { |
||
| 469 | if ( in_array( $name, $skipParameters ) ) { |
||
| 470 | continue; |
||
| 471 | } |
||
| 472 | $form .= "\t" . Html::hidden( $name, $value ) . "\n"; |
||
| 473 | } |
||
| 474 | |||
| 475 | $tagFilter = ChangeTags::buildTagFilterSelector( $this->opts['tagfilter'] ); |
||
| 476 | |||
| 477 | if ( $tagFilter ) { |
||
| 478 | $filterSelection = Html::rawElement( |
||
| 479 | 'td', |
||
| 480 | [], |
||
| 481 | implode( ' ', $tagFilter ) |
||
| 482 | ); |
||
| 483 | } else { |
||
| 484 | $filterSelection = Html::rawElement( 'td', [ 'colspan' => 2 ], '' ); |
||
| 485 | } |
||
| 486 | |||
| 487 | $this->getOutput()->addModules( 'mediawiki.userSuggest' ); |
||
| 488 | |||
| 489 | $labelNewbies = Xml::radioLabel( |
||
| 490 | $this->msg( 'sp-contributions-newbies' )->text(), |
||
| 491 | 'contribs', |
||
| 492 | 'newbie', |
||
| 493 | 'newbie', |
||
| 494 | $this->opts['contribs'] == 'newbie', |
||
| 495 | [ 'class' => 'mw-input' ] |
||
| 496 | ); |
||
| 497 | $labelUsername = Xml::radioLabel( |
||
| 498 | $this->msg( 'sp-contributions-username' )->text(), |
||
| 499 | 'contribs', |
||
| 500 | 'user', |
||
| 501 | 'user', |
||
| 502 | $this->opts['contribs'] == 'user', |
||
| 503 | [ 'class' => 'mw-input' ] |
||
| 504 | ); |
||
| 505 | $input = Html::input( |
||
| 506 | 'target', |
||
| 507 | $this->opts['target'], |
||
| 508 | 'text', |
||
| 509 | [ |
||
| 510 | 'size' => '40', |
||
| 511 | 'required' => '', |
||
| 512 | 'class' => [ |
||
| 513 | 'mw-input', |
||
| 514 | 'mw-ui-input-inline', |
||
| 515 | 'mw-autocomplete-user', // used by mediawiki.userSuggest |
||
| 516 | ], |
||
| 517 | ] + ( |
||
| 518 | // Only autofocus if target hasn't been specified or in non-newbies mode |
||
| 519 | ( $this->opts['contribs'] === 'newbie' || $this->opts['target'] ) |
||
| 520 | ? [] : [ 'autofocus' => true ] |
||
| 521 | ) |
||
| 522 | ); |
||
| 523 | |||
| 524 | $targetSelection = Html::rawElement( |
||
| 525 | 'td', |
||
| 526 | [ 'colspan' => 2 ], |
||
| 527 | $labelNewbies . '<br />' . $labelUsername . ' ' . $input . ' ' |
||
| 528 | ); |
||
| 529 | |||
| 530 | $namespaceSelection = Xml::tags( |
||
| 531 | 'td', |
||
| 532 | [], |
||
| 533 | Xml::label( |
||
| 534 | $this->msg( 'namespace' )->text(), |
||
| 535 | 'namespace', |
||
| 536 | '' |
||
| 537 | ) . |
||
| 538 | Html::namespaceSelector( |
||
| 539 | [ 'selected' => $this->opts['namespace'], 'all' => '' ], |
||
| 540 | [ |
||
| 541 | 'name' => 'namespace', |
||
| 542 | 'id' => 'namespace', |
||
| 543 | 'class' => 'namespaceselector', |
||
| 544 | ] |
||
| 545 | ) . ' ' . |
||
| 546 | Html::rawElement( |
||
| 547 | 'span', |
||
| 548 | [ 'class' => 'mw-input-with-label' ], |
||
| 549 | Xml::checkLabel( |
||
| 550 | $this->msg( 'invert' )->text(), |
||
| 551 | 'nsInvert', |
||
| 552 | 'nsInvert', |
||
| 553 | $this->opts['nsInvert'], |
||
| 554 | [ |
||
| 555 | 'title' => $this->msg( 'tooltip-invert' )->text(), |
||
| 556 | 'class' => 'mw-input' |
||
| 557 | ] |
||
| 558 | ) . ' ' |
||
| 559 | ) . |
||
| 560 | Html::rawElement( 'span', [ 'class' => 'mw-input-with-label' ], |
||
| 561 | Xml::checkLabel( |
||
| 562 | $this->msg( 'namespace_association' )->text(), |
||
| 563 | 'associated', |
||
| 564 | 'associated', |
||
| 565 | $this->opts['associated'], |
||
| 566 | [ |
||
| 567 | 'title' => $this->msg( 'tooltip-namespace_association' )->text(), |
||
| 568 | 'class' => 'mw-input' |
||
| 569 | ] |
||
| 570 | ) . ' ' |
||
| 571 | ) |
||
| 572 | ); |
||
| 573 | |||
| 574 | $filters = []; |
||
| 575 | |||
| 576 | if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) { |
||
| 577 | $filters[] = Html::rawElement( |
||
| 578 | 'span', |
||
| 579 | [ 'class' => 'mw-input-with-label' ], |
||
| 580 | Xml::checkLabel( |
||
| 581 | $this->msg( 'history-show-deleted' )->text(), |
||
| 582 | 'deletedOnly', |
||
| 583 | 'mw-show-deleted-only', |
||
| 584 | $this->opts['deletedOnly'], |
||
| 585 | [ 'class' => 'mw-input' ] |
||
| 586 | ) |
||
| 587 | ); |
||
| 588 | } |
||
| 589 | |||
| 590 | $filters[] = Html::rawElement( |
||
| 591 | 'span', |
||
| 592 | [ 'class' => 'mw-input-with-label' ], |
||
| 593 | Xml::checkLabel( |
||
| 594 | $this->msg( 'sp-contributions-toponly' )->text(), |
||
| 595 | 'topOnly', |
||
| 596 | 'mw-show-top-only', |
||
| 597 | $this->opts['topOnly'], |
||
| 598 | [ 'class' => 'mw-input' ] |
||
| 599 | ) |
||
| 600 | ); |
||
| 601 | $filters[] = Html::rawElement( |
||
| 602 | 'span', |
||
| 603 | [ 'class' => 'mw-input-with-label' ], |
||
| 604 | Xml::checkLabel( |
||
| 605 | $this->msg( 'sp-contributions-newonly' )->text(), |
||
| 606 | 'newOnly', |
||
| 607 | 'mw-show-new-only', |
||
| 608 | $this->opts['newOnly'], |
||
| 609 | [ 'class' => 'mw-input' ] |
||
| 610 | ) |
||
| 611 | ); |
||
| 612 | |||
| 613 | Hooks::run( |
||
| 614 | 'SpecialContributions::getForm::filters', |
||
| 615 | [ $this, &$filters ] |
||
| 616 | ); |
||
| 617 | |||
| 618 | $extraOptions = Html::rawElement( |
||
| 619 | 'td', |
||
| 620 | [ 'colspan' => 2 ], |
||
| 621 | implode( '', $filters ) |
||
| 622 | ); |
||
| 623 | |||
| 624 | $dateSelectionAndSubmit = Xml::tags( 'td', [ 'colspan' => 2 ], |
||
| 625 | Xml::dateMenu( |
||
| 626 | $this->opts['year'] === '' ? MWTimestamp::getInstance()->format( 'Y' ) : $this->opts['year'], |
||
| 627 | $this->opts['month'] |
||
| 628 | ) . ' ' . |
||
| 629 | Html::submitButton( |
||
| 630 | $this->msg( 'sp-contributions-submit' )->text(), |
||
| 631 | [ 'class' => 'mw-submit' ], [ 'mw-ui-progressive' ] |
||
| 632 | ) |
||
| 633 | ); |
||
| 634 | |||
| 635 | $form .= Xml::fieldset( $this->msg( 'sp-contributions-search' )->text() ); |
||
| 636 | $form .= Html::rawElement( 'table', [ 'class' => 'mw-contributions-table' ], "\n" . |
||
| 637 | Html::rawElement( 'tr', [], $targetSelection ) . "\n" . |
||
| 638 | Html::rawElement( 'tr', [], $namespaceSelection ) . "\n" . |
||
| 639 | Html::rawElement( 'tr', [], $filterSelection ) . "\n" . |
||
| 640 | Html::rawElement( 'tr', [], $extraOptions ) . "\n" . |
||
| 641 | Html::rawElement( 'tr', [], $dateSelectionAndSubmit ) . "\n" |
||
| 642 | ); |
||
| 643 | |||
| 644 | $explain = $this->msg( 'sp-contributions-explain' ); |
||
| 645 | if ( !$explain->isBlank() ) { |
||
| 646 | $form .= "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>"; |
||
| 647 | } |
||
| 648 | |||
| 649 | $form .= Xml::closeElement( 'fieldset' ) . Xml::closeElement( 'form' ); |
||
| 650 | |||
| 651 | return $form; |
||
| 652 | } |
||
| 653 | |||
| 676 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: