| Conditions | 12 |
| Paths | 144 |
| Total Lines | 45 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 87 | public function html() { |
||
| 88 | |||
| 89 | if ( $this->multiselect === true && ! is_array( $this->value ) ) { |
||
|
|
|||
| 90 | $this->value = explode( ',', $this->value ); |
||
| 91 | } |
||
| 92 | |||
| 93 | if ( $this->default ) { |
||
| 94 | if ( empty( $this->value ) || $this->value == '' ) { |
||
| 95 | $this->value = $this->default; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | ?> |
||
| 100 | <select name="<?php echo $this->name; ?><?php if ( $this->multiselect === true ) { echo '[]'; } ?>" |
||
| 101 | id="<?php echo $this->id; ?>" |
||
| 102 | style="<?php echo $this->style; ?>" |
||
| 103 | class="<?php echo $this->class; ?>" |
||
| 104 | <?php echo $this->attributes; ?> |
||
| 105 | <?php echo ( $this->multiselect === true ) ? ' multiple="multiple"' : ''; ?>> |
||
| 106 | <?php |
||
| 107 | |||
| 108 | if ( $this->allow_void === true ) { |
||
| 109 | echo '<option value=""' . selected( '', $this->value, false ) . '></option>'; |
||
| 110 | } |
||
| 111 | |||
| 112 | foreach ( $this->options as $option => $name ) { |
||
| 113 | if ( is_array( $this->value ) ) { |
||
| 114 | $selected = selected( in_array( $option, $this->value ), true, false ); |
||
| 115 | } else { |
||
| 116 | $selected = selected( $this->value, trim( strval( $option ) ), false ); |
||
| 117 | } |
||
| 118 | echo '<option value="' . $option . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
||
| 119 | } |
||
| 120 | |||
| 121 | ?> |
||
| 122 | </select> |
||
| 123 | <?php |
||
| 124 | |||
| 125 | echo $this->tooltip; |
||
| 126 | |||
| 127 | if ( ! empty( $this->description ) ) { |
||
| 128 | echo '<p class="description">' . wp_kses_post( $this->description ) . '</p>'; |
||
| 129 | } |
||
| 130 | |||
| 131 | } |
||
| 132 | |||
| 134 |