| Conditions | 11 |
| Paths | 384 |
| Total Lines | 52 |
| Code Lines | 25 |
| 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 |
||
| 128 | function getOutput() { |
||
| 129 | |||
| 130 | $settings_title = sprintf(__('Configure %s Settings', 'gravityview'), ucfirst($this->label_type)); |
||
| 131 | $delete_title = sprintf(__('Remove %s', 'gravityview'), ucfirst($this->label_type)); |
||
| 132 | $single_link_title = __('This field links to the Single Entry', 'gravityview'); |
||
| 133 | |||
| 134 | // $settings_html will just be hidden inputs if empty. Otherwise, it'll have an <ul>. Ugly hack, I know. |
||
| 135 | // TODO: Un-hack this |
||
| 136 | $hide_settings_link = ( empty( $this->item['settings_html'] ) || strpos( $this->item['settings_html'], '<!-- No Options -->') > 0 ) ? 'hide-if-js' : ''; |
||
| 137 | $settings_link = sprintf( '<a href="#settings" class="dashicons-admin-generic dashicons %s" title="%s"></a>', $hide_settings_link, esc_attr( $settings_title ) ); |
||
| 138 | |||
| 139 | // Should we show the icon that the field is being used as a link to single entry? |
||
| 140 | $hide_show_as_link_class = empty( $this->settings['show_as_link'] ) ? 'hide-if-js' : ''; |
||
| 141 | $show_as_link = '<span class="dashicons dashicons-admin-links '.$hide_show_as_link_class.'" title="'.esc_attr( $single_link_title ).'"></span>'; |
||
| 142 | |||
| 143 | // When a field label is empty, use the Field ID |
||
| 144 | $label = empty( $this->title ) ? sprintf( _x('Field #%s (No Label)', 'Label in field picker for empty label', 'gravityview'), $this->id ) : $this->title; |
||
| 145 | |||
| 146 | // If there's a custom label, and show label is checked, use that as the field heading |
||
| 147 | if( !empty( $this->settings['custom_label'] ) && !empty( $this->settings['show_label'] ) ) { |
||
| 148 | $label = $this->settings['custom_label']; |
||
| 149 | } else if( !empty( $this->item['customLabel'] ) ) { |
||
| 150 | $label = $this->item['customLabel']; |
||
| 151 | } |
||
| 152 | |||
| 153 | $output = '<h5 class="selectable gfield field-id-'.esc_attr($this->id).'">'; |
||
| 154 | |||
| 155 | $label = esc_attr( $label ); |
||
| 156 | |||
| 157 | if( !empty( $this->item['parent'] ) ) { |
||
| 158 | $label .= ' <small>('.esc_attr( $this->item['parent']['label'] ) .')</small>'; |
||
| 159 | } |
||
| 160 | |||
| 161 | // Name of field / widget |
||
| 162 | $output .= '<span class="gv-field-label" data-original-title="'.esc_attr( $label ).'" title="'. $this->get_item_info( false ) .'">'. $label . '</span>'; |
||
| 163 | |||
| 164 | |||
| 165 | $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>'; |
||
| 166 | |||
| 167 | // Displays only in the field/widget picker. |
||
| 168 | if( $field_info = $this->get_item_info() ) { |
||
| 169 | $output .= '<span class="gv-field-info">'.$field_info.'</span>'; |
||
| 170 | } |
||
| 171 | |||
| 172 | $output .= '</h5>'; |
||
| 173 | |||
| 174 | $container_class = !empty( $this->item['parent'] ) ? ' gv-child-field' : ''; |
||
| 175 | |||
| 176 | $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>'; |
||
| 177 | |||
| 178 | return $output; |
||
| 179 | } |
||
| 180 | |||
| 182 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.