| Conditions | 4 |
| Paths | 6 |
| Total Lines | 93 |
| 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 |
||
| 117 | public function form( $instance ) { |
||
| 118 | $defaults = array( |
||
| 119 | 'title' => '', |
||
| 120 | 'id' => '', |
||
| 121 | 'float_labels' => 'global', |
||
| 122 | 'display_style' => 'modal', |
||
| 123 | 'show_content' => 'none', |
||
| 124 | 'continue_button_title' => '', |
||
| 125 | ); |
||
| 126 | |||
| 127 | $instance = wp_parse_args( (array) $instance, $defaults ); |
||
| 128 | |||
| 129 | // Backward compatibility: Set float labels as default if, it was set as empty previous. |
||
| 130 | $instance['float_labels'] = empty( $instance['float_labels'] ) ? 'global' : $instance['float_labels']; |
||
| 131 | |||
| 132 | // Query Give Forms. |
||
| 133 | $args = array( |
||
| 134 | 'post_type' => 'give_forms', |
||
| 135 | 'posts_per_page' => - 1, |
||
| 136 | 'post_status' => 'publish', |
||
| 137 | ); |
||
| 138 | |||
| 139 | $give_forms = get_posts( $args ); |
||
| 140 | ?> |
||
| 141 | <div class="give_forms_widget_container"> |
||
| 142 | |||
| 143 | <?php // Widget: widget Title. ?> |
||
| 144 | <p> |
||
| 145 | <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'give' ); ?></label> |
||
| 146 | <input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" /><br> |
||
| 147 | <small class="give-field-description"><?php esc_html_e( 'Leave blank to hide the widget title.', 'give' ); ?></small> |
||
| 148 | </p> |
||
| 149 | |||
| 150 | <?php // Widget: Give Form. ?> |
||
| 151 | <p> |
||
| 152 | <label for="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>"><?php esc_html_e( 'Give Form:', 'give' ); ?></label> |
||
| 153 | <select class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'id' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>"> |
||
| 154 | <option value="current"><?php esc_html_e( '- Select -', 'give' ); ?></option> |
||
| 155 | <?php foreach ( $give_forms as $give_form ) { ?> |
||
| 156 | <?php /* translators: %s: Title */ ?> |
||
| 157 | <?php $form_title = empty( $give_form->post_title ) ? sprintf( __( 'Untitled (#%s)', 'give' ), $give_form->ID ) : $give_form->post_title; ?> |
||
| 158 | <option <?php selected( absint( $instance['id'] ), $give_form->ID ); ?> value="<?php echo esc_attr( $give_form->ID ); ?>"><?php echo esc_html( $form_title ); ?></option> |
||
| 159 | <?php } ?> |
||
| 160 | </select><br> |
||
| 161 | <small class="give-field-description"><?php esc_html_e( 'Select a Give Form to embed in this widget.', 'give' ); ?></small> |
||
| 162 | </p> |
||
| 163 | |||
| 164 | <?php // Widget: Display Style. ?> |
||
| 165 | <p class="give_forms_display_style_setting_row"> |
||
| 166 | <label for="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>"><?php esc_html_e( 'Display Style:', 'give' ); ?></label><br> |
||
| 167 | <label for="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>-onpage"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>-onpage" name="<?php echo esc_attr( $this->get_field_name( 'display_style' ) ); ?>" value="onpage" <?php checked( $instance['display_style'], 'onpage' ); ?>> <?php echo esc_html__( 'All Fields', 'give' ); ?></label> |
||
| 168 | <label for="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>-reveal"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>-reveal" name="<?php echo esc_attr( $this->get_field_name( 'display_style' ) ); ?>" value="reveal" <?php checked( $instance['display_style'], 'reveal' ); ?>> <?php echo esc_html__( 'Reveal', 'give' ); ?></label> |
||
| 169 | <label for="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>-modal"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>-modal" name="<?php echo esc_attr( $this->get_field_name( 'display_style' ) ); ?>" value="modal" <?php checked( $instance['display_style'], 'modal' ); ?>> <?php echo esc_html__( 'Modal', 'give' ); ?></label> |
||
| 170 | <label for="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>-button"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>-button" name="<?php echo esc_attr( $this->get_field_name( 'display_style' ) ); ?>" value="button" <?php checked( $instance['display_style'], 'button' ); ?>> <?php echo esc_html__( 'Button', 'give' ); ?></label><br> |
||
| 171 | <small class="give-field-description"> |
||
| 172 | <?php echo esc_html__( 'Select a Give Form style.', 'give' ); ?> |
||
| 173 | </small> |
||
| 174 | </p> |
||
| 175 | |||
| 176 | <?php // Widget: Continue Button Title. ?> |
||
| 177 | <p class="give_forms_continue_button_title_setting_row"> |
||
| 178 | <label for="<?php echo esc_attr( $this->get_field_id( 'continue_button_title' ) ); ?>"><?php esc_html_e( 'Button Text:', 'give' ); ?></label> |
||
| 179 | <input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'continue_button_title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'continue_button_title' ) ); ?>" value="<?php echo esc_attr( $instance['continue_button_title'] ); ?>" /><br> |
||
| 180 | <small class="give-field-description"><?php esc_html_e( 'The button label for displaying the additional payment fields.', 'give' ); ?></small> |
||
| 181 | </p> |
||
| 182 | |||
| 183 | <?php // Widget: Floating Labels. ?> |
||
| 184 | <p> |
||
| 185 | <label for="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>"><?php esc_html_e( 'Floating Labels (optional):', 'give' ); ?></label><br> |
||
| 186 | <label for="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>-global"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>-global" name="<?php echo esc_attr( $this->get_field_name( 'float_labels' ) ); ?>" value="global" <?php checked( $instance['float_labels'], 'global' ); ?>> <?php echo esc_html__( 'Global Option', 'give' ); ?></label> |
||
| 187 | <label for="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>-enabled"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>-enabled" name="<?php echo esc_attr( $this->get_field_name( 'float_labels' ) ); ?>" value="enabled" <?php checked( $instance['float_labels'], 'enabled' ); ?>> <?php echo esc_html__( 'Enabled', 'give' ); ?></label> |
||
| 188 | <label for="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>-disabled"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>-disabled" name="<?php echo esc_attr( $this->get_field_name( 'float_labels' ) ); ?>" value="disabled" <?php checked( $instance['float_labels'], 'disabled' ); ?>> <?php echo esc_html__( 'Disabled', 'give' ); ?></label><br> |
||
| 189 | <small class="give-field-description"> |
||
| 190 | <?php |
||
| 191 | printf( |
||
| 192 | /* translators: %s: Documentation link to http://docs.givewp.com/form-floating-labels */ |
||
| 193 | __( 'Override the <a href="%s" target="_blank">floating labels</a> setting for this Give form.', 'give' ), |
||
| 194 | esc_url( 'http://docs.givewp.com/form-floating-labels' ) |
||
| 195 | ); |
||
| 196 | ?> |
||
| 197 | </small> |
||
| 198 | </p> |
||
| 199 | |||
| 200 | <?php // Widget: Display Content. ?> |
||
| 201 | <p> |
||
| 202 | <label for="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>"><?php esc_html_e( 'Display Content (optional):', 'give' ); ?></label><br> |
||
| 203 | <label for="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>-none"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>-none" name="<?php echo esc_attr( $this->get_field_name( 'show_content' ) ); ?>" value="none" <?php checked( $instance['show_content'], 'none' ); ?>> <?php echo esc_html__( 'None', 'give' ); ?></label> |
||
| 204 | <label for="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>-above"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>-above" name="<?php echo esc_attr( $this->get_field_name( 'show_content' ) ); ?>" value="above" <?php checked( $instance['show_content'], 'above' ); ?>> <?php echo esc_html__( 'Above', 'give' ); ?></label> |
||
| 205 | <label for="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>-below"><input type="radio" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>-below" name="<?php echo esc_attr( $this->get_field_name( 'show_content' ) ); ?>" value="below" <?php checked( $instance['show_content'], 'below' ); ?>> <?php echo esc_html__( 'Below', 'give' ); ?></label><br> |
||
| 206 | <small class="give-field-description"><?php esc_html_e( 'Override the display content setting for this Give form.', 'give' ); ?></small> |
||
| 207 | </div> |
||
| 208 | <?php |
||
| 209 | } |
||
| 210 | |||
| 245 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.