| Conditions | 11 |
| Paths | 384 |
| Total Lines | 52 |
| Code Lines | 25 |
| 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 |
||
| 171 | function getOutput() { |
||
| 172 | |||
| 173 | $settings_title = sprintf(__('Configure %s Settings', 'gravityview'), ucfirst($this->label_type)); |
||
| 174 | $delete_title = sprintf(__('Remove %s', 'gravityview'), ucfirst($this->label_type)); |
||
| 175 | $single_link_title = __('This field links to the Single Entry', 'gravityview'); |
||
| 176 | |||
| 177 | // $settings_html will just be hidden inputs if empty. Otherwise, it'll have an <ul>. Ugly hack, I know. |
||
| 178 | // TODO: Un-hack this |
||
| 179 | $hide_settings_link = ( empty( $this->item['settings_html'] ) || strpos( $this->item['settings_html'], '<!-- No Options -->') > 0 ) ? 'hide-if-js' : ''; |
||
| 180 | $settings_link = sprintf( '<a href="#settings" class="dashicons-admin-generic dashicons %s" title="%s"></a>', $hide_settings_link, esc_attr( $settings_title ) ); |
||
| 181 | |||
| 182 | // Should we show the icon that the field is being used as a link to single entry? |
||
| 183 | $hide_show_as_link_class = empty( $this->settings['show_as_link'] ) ? 'hide-if-js' : ''; |
||
| 184 | $show_as_link = '<span class="dashicons dashicons-admin-links '.$hide_show_as_link_class.'" title="'.esc_attr( $single_link_title ).'"></span>'; |
||
| 185 | |||
| 186 | // When a field label is empty, use the Field ID |
||
| 187 | $label = empty( $this->title ) ? sprintf( _x('Field #%s (No Label)', 'Label in field picker for empty label', 'gravityview'), $this->id ) : $this->title; |
||
| 188 | |||
| 189 | // If there's a custom label, and show label is checked, use that as the field heading |
||
| 190 | if( !empty( $this->settings['custom_label'] ) && !empty( $this->settings['show_label'] ) ) { |
||
| 191 | $label = $this->settings['custom_label']; |
||
| 192 | } else if( !empty( $this->item['customLabel'] ) ) { |
||
| 193 | $label = $this->item['customLabel']; |
||
| 194 | } |
||
| 195 | |||
| 196 | $output = '<h5 class="selectable gfield field-id-'.esc_attr($this->id).'">'; |
||
| 197 | |||
| 198 | $label = esc_attr( $label ); |
||
| 199 | |||
| 200 | if( !empty( $this->item['parent'] ) ) { |
||
| 201 | $label .= ' <small>('.esc_attr( $this->item['parent']['label'] ) .')</small>'; |
||
| 202 | } |
||
| 203 | |||
| 204 | // Name of field / widget |
||
| 205 | $output .= '<span class="gv-field-label" data-original-title="'.esc_attr( $label ).'" title="'. $this->get_item_info( false ) .'">'. $label . '</span>'; |
||
| 206 | |||
| 207 | |||
| 208 | $output .= '<span class="gv-field-controls">'.$settings_link.$show_as_link.'<a href="#remove" class="dashicons-dismiss dashicons" title="'.esc_attr( $delete_title ) .'"></a></span>'; |
||
| 209 | |||
| 210 | // Displays only in the field/widget picker. |
||
| 211 | if( $field_info = $this->get_item_info() ) { |
||
| 212 | $output .= '<span class="gv-field-info">'.$field_info.'</span>'; |
||
| 213 | } |
||
| 214 | |||
| 215 | $output .= '</h5>'; |
||
| 216 | |||
| 217 | $container_class = !empty( $this->item['parent'] ) ? ' gv-child-field' : ''; |
||
| 218 | |||
| 219 | $output = '<div data-fieldid="'.esc_attr($this->id).'" data-inputtype="'.esc_attr( $this->item['input_type'] ).'" class="gv-fields'.$container_class.'">'.$output.$this->item['settings_html'].'</div>'; |
||
| 220 | |||
| 221 | return $output; |
||
| 222 | } |
||
| 223 | |||
| 225 |