| Conditions | 15 |
| Paths | 1476 |
| Total Lines | 81 |
| Code Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 50 | function getButtons() { |
||
| 51 | $buttons = ''; |
||
| 52 | |||
| 53 | // IE<8 has bugs with <button>, so we'll need to avoid them. |
||
| 54 | $isBadIE = preg_match( '/MSIE [1-7]\./i', $this->getRequest()->getHeader( 'User-Agent' ) ); |
||
| 55 | |||
| 56 | if ( $this->mShowSubmit ) { |
||
| 57 | $attribs = [ 'infusable' => true ]; |
||
| 58 | |||
| 59 | if ( isset( $this->mSubmitID ) ) { |
||
| 60 | $attribs['id'] = $this->mSubmitID; |
||
| 61 | } |
||
| 62 | |||
| 63 | if ( isset( $this->mSubmitName ) ) { |
||
| 64 | $attribs['name'] = $this->mSubmitName; |
||
| 65 | } |
||
| 66 | |||
| 67 | if ( isset( $this->mSubmitTooltip ) ) { |
||
| 68 | $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip ); |
||
| 69 | } |
||
| 70 | |||
| 71 | $attribs['classes'] = [ 'mw-htmlform-submit' ]; |
||
| 72 | $attribs['type'] = 'submit'; |
||
| 73 | $attribs['label'] = $this->getSubmitText(); |
||
| 74 | $attribs['value'] = $this->getSubmitText(); |
||
| 75 | $attribs['flags'] = $this->mSubmitFlags; |
||
| 76 | $attribs['useInputTag'] = $isBadIE; |
||
| 77 | |||
| 78 | $buttons .= new OOUI\ButtonInputWidget( $attribs ); |
||
| 79 | } |
||
| 80 | |||
| 81 | if ( $this->mShowReset ) { |
||
| 82 | $buttons .= new OOUI\ButtonInputWidget( [ |
||
| 83 | 'type' => 'reset', |
||
| 84 | 'label' => $this->msg( 'htmlform-reset' )->text(), |
||
| 85 | 'useInputTag' => $isBadIE, |
||
| 86 | ] ); |
||
| 87 | } |
||
| 88 | |||
| 89 | foreach ( $this->mButtons as $button ) { |
||
| 90 | $attrs = []; |
||
| 91 | |||
| 92 | if ( $button['attribs'] ) { |
||
| 93 | $attrs += $button['attribs']; |
||
| 94 | } |
||
| 95 | |||
| 96 | if ( isset( $button['id'] ) ) { |
||
| 97 | $attrs['id'] = $button['id']; |
||
| 98 | } |
||
| 99 | |||
| 100 | if ( $isBadIE ) { |
||
| 101 | $label = $button['value']; |
||
| 102 | } elseif ( isset( $button['label-message'] ) ) { |
||
| 103 | $label = new OOUI\HtmlSnippet( $this->getMessage( $button['label-message'] )->parse() ); |
||
| 104 | } elseif ( isset( $button['label'] ) ) { |
||
| 105 | $label = $button['label']; |
||
| 106 | } elseif ( isset( $button['label-raw'] ) ) { |
||
| 107 | $label = new OOUI\HtmlSnippet( $button['label-raw'] ); |
||
| 108 | } else { |
||
| 109 | $label = $button['value']; |
||
| 110 | } |
||
| 111 | |||
| 112 | $attrs['classes'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : []; |
||
| 113 | |||
| 114 | $buttons .= new OOUI\ButtonInputWidget( [ |
||
| 115 | 'type' => 'submit', |
||
| 116 | 'name' => $button['name'], |
||
| 117 | 'value' => $button['value'], |
||
| 118 | 'label' => $label, |
||
| 119 | 'flags' => $button['flags'], |
||
| 120 | 'useInputTag' => $isBadIE, |
||
| 121 | ] + $attrs ); |
||
| 122 | } |
||
| 123 | |||
| 124 | if ( !$buttons ) { |
||
| 125 | return ''; |
||
| 126 | } |
||
| 127 | |||
| 128 | return Html::rawElement( 'div', |
||
| 129 | [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n"; |
||
| 130 | } |
||
| 131 | |||
| 262 |