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