| Conditions | 4 |
| Paths | 6 |
| Total Lines | 55 |
| Code Lines | 28 |
| 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 |
||
| 128 | public function html_input( $default_entity_identifier ) { |
||
| 129 | |||
| 130 | if ( empty( $default_entity_identifier ) ) { |
||
| 131 | $entity = null; |
||
| 132 | } elseif ( is_numeric( $default_entity_identifier ) ) { |
||
| 133 | $entity = get_post( $default_entity_identifier ); |
||
| 134 | } else { |
||
| 135 | // @todo: we cannot be so sure this is a URI. |
||
| 136 | // It is an URI |
||
| 137 | $entity = Wordlift_Entity_Service |
||
| 138 | ::get_instance() |
||
| 139 | ->get_entity_post_by_uri( $default_entity_identifier ); |
||
| 140 | } |
||
| 141 | |||
| 142 | if ( ! is_null( $entity ) ) { |
||
| 143 | $label = $entity->post_title; |
||
| 144 | $value = $entity->ID; |
||
| 145 | } else { |
||
| 146 | // No ID and no internal uri. Just leave as is. |
||
| 147 | $label = $default_entity_identifier; |
||
| 148 | $value = $default_entity_identifier; |
||
| 149 | } |
||
| 150 | |||
| 151 | // Write saved value in page |
||
| 152 | // The <input> tags host the meta value. |
||
| 153 | // The visible <input> has the human readable value (i.e. entity name or uri) |
||
| 154 | // and is accompained by an hidden <input> tag, passed to the server, |
||
| 155 | // that contains the raw value (i.e. the uri or entity id). |
||
| 156 | @ob_start(); |
||
| 157 | ?> |
||
| 158 | <div class="wl-input-wrapper wl-autocomplete-wrapper"> |
||
| 159 | <input |
||
| 160 | type="text" |
||
| 161 | class="<?php echo esc_attr( $this->meta_name ); ?> wl-autocomplete" |
||
| 162 | value="<?php echo esc_attr( $label ); ?>" |
||
| 163 | style="width:88%" |
||
| 164 | /> |
||
| 165 | <input |
||
| 166 | type="hidden" |
||
| 167 | class="<?php echo esc_attr( $this->meta_name ); ?>" |
||
| 168 | name="wl_metaboxes[<?php echo $this->meta_name ?>][]" |
||
| 169 | value="<?php echo esc_attr( $value ); ?>" |
||
| 170 | /> |
||
| 171 | |||
| 172 | <button class="button wl-remove-input wl-button" type="button"> |
||
| 173 | <?php esc_html_e( 'Remove', 'wordlift' ); ?> |
||
| 174 | </button> |
||
| 175 | |||
| 176 | <div class="wl-input-notice"></div> |
||
| 177 | </div> |
||
| 178 | <?php |
||
| 179 | $html = ob_get_clean(); |
||
| 180 | |||
| 181 | return $html; |
||
| 182 | } |
||
| 183 | |||
| 185 |
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.