| Conditions | 20 |
| Paths | 9216 |
| Total Lines | 90 |
| Code Lines | 71 |
| 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 |
||
| 64 | public function form( $instance ) { |
||
| 65 | $options = get_option( 'podlove_psb_defaults' ); |
||
| 66 | |||
| 67 | $title = isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : ''; |
||
| 68 | $button = isset( $instance[ 'button' ] ) ? $instance[ 'button' ] : ''; |
||
| 69 | $size = isset( $instance[ 'size' ] ) ? $instance[ 'size' ] : $options['size']; |
||
| 70 | $style = isset( $instance[ 'style' ] ) ? $instance[ 'style' ] : $options['style']; |
||
| 71 | $format = isset( $instance[ 'format' ] ) ? $instance[ 'format' ] : $options['format']; |
||
| 72 | $autowidth = isset( $instance[ 'autowidth' ] ) ? $instance[ 'autowidth' ] : true; |
||
| 73 | $infotext = isset( $instance[ 'infotext' ] ) ? $instance[ 'infotext' ] : ''; |
||
| 74 | $color = isset( $instance[ 'color' ] ) ? $instance[ 'color' ] : $options['color']; |
||
| 75 | $language = isset( $instance[ 'language' ] ) ? $instance[ 'language' ] : $options['language']; |
||
| 76 | |||
| 77 | $buttons = Model\Button::all(); |
||
| 78 | if ( is_multisite() ) { |
||
| 79 | $network_buttons = Model\NetworkButton::all(); |
||
| 80 | } |
||
| 81 | ?> |
||
| 82 | <p> |
||
| 83 | <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'podlove-subscribe-button' ); ?></label> |
||
| 84 | <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $title; ?>" /> |
||
| 85 | <label for="<?php echo $this->get_field_id( 'color' ); ?>"><?php _e( 'Color', 'podlove-subscribe-button' ); ?></label> |
||
| 86 | <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 $color; ?>" /> |
||
| 87 | <style type="text/css"> |
||
| 88 | .sp-replacer { |
||
| 89 | display: flex; |
||
| 90 | } |
||
| 91 | .sp-preview { |
||
| 92 | flex-grow: 10; |
||
| 93 | } |
||
| 94 | </style> |
||
| 95 | <label for="<?php echo $this->get_field_id( 'button' ); ?>"><?php _e( 'Button', 'podlove-subscribe-button' ); ?></label> |
||
| 96 | <select class="widefat" id="<?php echo $this->get_field_id( 'button' ); ?>" |
||
| 97 | name="<?php echo $this->get_field_name( 'button' ); ?>"> |
||
| 98 | <?php if ( isset( $network_buttons ) && count( $network_buttons ) > 0 ) : ?> |
||
| 99 | <optgroup label="<?php _e( 'Local', 'podlove-subscribe-button' ); ?>"> |
||
| 100 | <?php |
||
| 101 | foreach ( $buttons as $subscribebutton ) { |
||
| 102 | echo "<option value='" . $subscribebutton->name . "' " . selected( $subscribebutton->name, $button ) . " >" . $subscribebutton->title . " (" . $subscribebutton->name . ")</option>"; |
||
| 103 | } ?> |
||
| 104 | </optgroup> |
||
| 105 | <optgroup label="<?php _e( 'Network', 'podlove-subscribe-button' ); ?>"> |
||
| 106 | <?php |
||
| 107 | foreach ( $network_buttons as $subscribebutton ) { |
||
| 108 | echo "<option value='" . $subscribebutton->name . "' " . selected( $subscribebutton->name, $button ) . " >" . $subscribebutton->title . " (" . $subscribebutton->name . ")</option>"; |
||
| 109 | } ?> |
||
| 110 | </optgroup> |
||
| 111 | <?php else : |
||
| 112 | foreach ( $buttons as $subscribebutton ) { |
||
| 113 | echo "<option value='" . $subscribebutton->name . "' " . selected( $subscribebutton->name, $button ) . " >" . $subscribebutton->title . " (" . $subscribebutton->name . ")</option>"; |
||
| 114 | } |
||
| 115 | endif; ?> |
||
| 116 | </select> |
||
| 117 | <?php |
||
| 118 | $customize_options = array( |
||
| 119 | 'size' => array( |
||
| 120 | 'name' => __( 'Size', 'podlove-subscribe-button' ), |
||
| 121 | 'options' => Defaults::button( 'size' ), |
||
| 122 | ), |
||
| 123 | 'style' => array( |
||
| 124 | 'name' => __( 'Style', 'podlove-subscribe-button' ), |
||
| 125 | 'options' => Defaults::button( 'style' ), |
||
| 126 | ), |
||
| 127 | 'format' => array( |
||
| 128 | 'name' => __( 'Format', 'podlove-subscribe-button' ), |
||
| 129 | 'options' => Defaults::button( 'format' ), |
||
| 130 | ), |
||
| 131 | 'autowidth' => array( |
||
| 132 | 'name' => __( 'Autowidth', 'podlove-subscribe-button' ), |
||
| 133 | 'options' => Defaults::button( 'autowidth' ), |
||
| 134 | ), |
||
| 135 | 'language' => array( |
||
| 136 | 'name' => __( 'Language', 'podlove-subscribe-button' ), |
||
| 137 | 'options' => array_combine( Defaults::button( 'language' ), Defaults::button( 'language' ) ), |
||
| 138 | ), |
||
| 139 | ); |
||
| 140 | |||
| 141 | foreach ( $customize_options as $slug => $properties ) : ?> |
||
| 142 | <label for="<?php echo $this->get_field_id( $slug ); ?>"><?php echo $properties[ 'name' ]; ?></label> |
||
| 143 | <select class="widefat" id="<?php echo $this->get_field_id( $slug ); ?>" name="<?php echo $this->get_field_name( $slug ); ?>"> |
||
| 144 | <option value="default" <?php echo ( $$slug == 'default' ? 'selected="selected"' : '' ); ?>><?php printf( __( 'Default %s', 'podlove-subscribe-button' ), $properties[ 'name' ] ) ?></option> |
||
| 145 | <optgroup> |
||
| 146 | <?php foreach ( $properties[ 'options' ] as $property => $name ) : ?> |
||
| 147 | <option value="<?php echo $property; ?>" <?php echo ( $$slug == $property ? 'selected="selected"' : '' ); ?>><?php echo $name; ?></option> |
||
| 148 | <?php endforeach; ?> |
||
| 149 | </optgroup> |
||
| 150 | </select> |
||
| 151 | <?php endforeach; ?> |
||
| 152 | <label for="<?php echo $this->get_field_id( 'infotext' ); ?>"><?php _e( 'Description', 'podlove-subscribe-button' ); ?></label> |
||
| 153 | <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> |
||
| 154 | </p> |
||
| 171 |