| Conditions | 19 |
| Paths | 4608 |
| Total Lines | 89 |
| Code Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 17 | ||
| Bugs | 6 | 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 |
||
| 49 | public function form( $instance ) { |
||
| 50 | |||
| 51 | $title = isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : ''; |
||
| 52 | $button = isset( $instance[ 'button' ] ) ? $instance[ 'button' ] : ''; |
||
| 53 | $size = isset( $instance[ 'size' ] ) ? $instance[ 'size' ] : 'big'; |
||
| 54 | $style = isset( $instance[ 'style' ] ) ? $instance[ 'style' ] : 'filled'; |
||
| 55 | $format = isset( $instance[ 'format' ] ) ? $instance[ 'format' ] : 'cover'; |
||
| 56 | $autowidth = isset( $instance[ 'autowidth' ] ) ? $instance[ 'autowidth' ] : true; |
||
| 57 | $infotext = isset( $instance[ 'infotext' ] ) ? $instance[ 'infotext' ] : ''; |
||
| 58 | $color = isset( $instance[ 'color' ] ) ? $instance[ 'color' ] : '#75ad91'; |
||
| 59 | |||
| 60 | $buttons = \PodloveSubscribeButton\Model\Button::all(); |
||
| 61 | if ( is_multisite() ) |
||
| 62 | $network_buttons = \PodloveSubscribeButton\Model\NetworkButton::all(); |
||
| 63 | ?> |
||
| 64 | <p> |
||
| 65 | <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'podlove-subscribe-button' ); ?></label> |
||
| 66 | <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr($title); ?>" /> |
||
| 67 | |||
| 68 | <label for="<?php echo $this->get_field_id( 'color' ); ?>"><?php _e( 'Color', 'podlove-subscribe-button' ); ?></label> |
||
| 69 | <input class="podlove_subscribe_button_color" id="<?php echo $this->get_field_id( 'color' ); ?>" name="<?php echo $this->get_field_name( 'color' ); ?>" value="<?php echo esc_attr($color); ?>" /> |
||
| 70 | <style type="text/css"> |
||
| 71 | .sp-replacer { |
||
| 72 | display: flex; |
||
| 73 | } |
||
| 74 | .sp-preview { |
||
| 75 | flex-grow: 10; |
||
| 76 | } |
||
| 77 | </style> |
||
| 78 | |||
| 79 | <label for="<?php echo $this->get_field_id( 'button' ); ?>"><?php _e( 'Button', 'podlove-subscribe-button' ); ?></label> |
||
| 80 | <select class="widefat" id="<?php echo $this->get_field_id( 'button' ); ?>" |
||
| 81 | name="<?php echo $this->get_field_name( 'button' ); ?>"> |
||
| 82 | <?php if ( isset($network_buttons) && count($network_buttons) > 0 ) : ?> |
||
| 83 | <optgroup label="<?php _e('Local', 'podlove'); ?>"> |
||
| 84 | <?php |
||
| 85 | foreach ($buttons as $subscribebutton) { |
||
| 86 | echo "<option value='" . sanitize_title($subscribebutton->name) . "' " . selected( sanitize_title($subscribebutton->name), $button ) . " >" . sanitize_title($subscribebutton->title) . " (" . sanitize_title($subscribebutton->name) . ")</option>"; |
||
| 87 | } |
||
| 88 | ?> |
||
| 89 | </optgroup> |
||
| 90 | <optgroup label="<?php _e('Network', 'podlove'); ?>"> |
||
| 91 | <?php |
||
| 92 | foreach ($network_buttons as $subscribebutton) { |
||
| 93 | echo "<option value='" . sanitize_title($subscribebutton->name) . "' " . selected( sanitize_title($subscribebutton->name), $button ) . " >" . sanitize_title($subscribebutton->title) . " (" . sanitize_title($subscribebutton->name) . ")</option>"; |
||
| 94 | } |
||
| 95 | ?> |
||
| 96 | </optgroup> |
||
| 97 | <?php else : |
||
| 98 | foreach ($buttons as $subscribebutton) { |
||
| 99 | echo "<option value='" . sanitize_title($subscribebutton->name) . "' " . selected( sanitize_title($subscribebutton->name), $button ) . " >" . sanitize_title($subscribebutton->title) . " (" . sanitize_title($subscribebutton->name) . ")</option>"; |
||
| 100 | } |
||
| 101 | endif; ?> |
||
| 102 | </select> |
||
| 103 | |||
| 104 | <?php |
||
| 105 | $customize_options = array( |
||
| 106 | 'size' => array( |
||
| 107 | 'name' => __( 'Size', 'podlove-subscribe-button' ), |
||
| 108 | 'options' => \PodloveSubscribeButton\Model\Button::$size |
||
| 109 | ), |
||
| 110 | 'style' => array( |
||
| 111 | 'name' => __( 'Style', 'podlove-subscribe-button' ), |
||
| 112 | 'options' => \PodloveSubscribeButton\Model\Button::$style |
||
| 113 | ), |
||
| 114 | 'format' => array( |
||
| 115 | 'name' => __( 'Format', 'podlove-subscribe-button' ), |
||
| 116 | 'options' => \PodloveSubscribeButton\Model\Button::$format |
||
| 117 | ), |
||
| 118 | 'autowidth' => array( |
||
| 119 | 'name' => __( 'Autowidth', 'podlove-subscribe-button' ), |
||
| 120 | 'options' => \PodloveSubscribeButton\Model\Button::$width |
||
| 121 | ) |
||
| 122 | ); |
||
| 123 | |||
| 124 | foreach ($customize_options as $slug => $properties) : ?> |
||
| 125 | <label for="<?php echo $this->get_field_id( $slug ); ?>"><?php echo $properties['name']; ?></label> |
||
| 126 | <select class="widefat" id="<?php echo $this->get_field_id( $slug ); ?>" name="<?php echo $this->get_field_name( $slug ); ?>"> |
||
| 127 | <option value="default" <?php echo ( $$slug == 'default' ? 'selected="selected"' : '' ); ?>><?php printf( __( 'Default %s', 'podlove-subscribe-button' ), $properties['name'] ) ?></option> |
||
| 128 | <optgroup> |
||
| 129 | <?php foreach ( $properties['options'] as $property => $name ) : ?> |
||
| 130 | <option value="<?php echo $property; ?>" <?php echo ( $$slug == $property ? 'selected="selected"' : '' ); ?>><?php echo $name; ?></option> |
||
| 131 | <?php endforeach; ?> |
||
| 132 | </optgroup> |
||
| 133 | </select> |
||
| 134 | <?php endforeach; ?> |
||
| 135 | |||
| 136 | <label for="<?php echo $this->get_field_id( 'infotext' ); ?>"><?php _e( 'Description', 'podlove-subscribe-button' ); ?></label> |
||
| 137 | <textarea class="widefat" rows="10" id="<?php echo $this->get_field_id( 'infotext' ); ?>" name="<?php echo $this->get_field_name( 'infotext' ); ?>"><?php echo $infotext; ?></textarea> |
||
| 138 | </p> |
||
| 155 |