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