| 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 |
||
| 49 | public function form( $instance ) { |
||
| 50 | foreach ( self::$widget_settings as $setting ) { |
||
| 51 | $$setting = isset( $instance[ $setting ] ) ? $instance[ $setting ] : ''; |
||
| 52 | } |
||
| 53 | |||
| 54 | $buttons = \PodloveSubscribeButton\Model\Button::all(); |
||
| 55 | if ( is_multisite() ) |
||
| 56 | $network_buttons = \PodloveSubscribeButton\Model\NetworkButton::all(); |
||
| 57 | |||
| 58 | $buttons_as_options = function( $buttons ) { |
||
| 59 | foreach ( $buttons as $subscribebutton ) { |
||
| 60 | echo "<option value='" . $subscribebutton->name . "' " . ( $subscribebutton->name == $button ? 'selected=\"selected\"' : '' ) . " >" . $subscribebutton->title . " (" . $subscribebutton->name . ")</option>"; |
||
| 61 | } |
||
| 62 | } |
||
| 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 $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 $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-subscribe-button' ); ?>"> |
||
| 84 | <?php $buttons_as_options( $buttons ); ?> |
||
| 85 | </optgroup> |
||
| 86 | <optgroup label="<?php _e( 'Network', 'podlove-subscribe-button' ); ?>"> |
||
| 87 | <?php $buttons_as_options( $network_buttons ); ?> |
||
| 88 | </optgroup> |
||
| 89 | <?php else : |
||
| 90 | $buttons_as_options( $buttons ); |
||
| 91 | endif; ?> |
||
| 92 | </select> |
||
| 93 | |||
| 94 | <?php |
||
| 95 | $customize_options = array( |
||
| 96 | 'size' => array( |
||
| 97 | 'name' => __( 'Size', 'podlove-subscribe-button' ), |
||
| 98 | 'options' => \PodloveSubscribeButton\Model\Button::$size |
||
| 99 | ), |
||
| 100 | 'style' => array( |
||
| 101 | 'name' => __( 'Style', 'podlove-subscribe-button' ), |
||
| 102 | 'options' => \PodloveSubscribeButton\Model\Button::$style |
||
| 103 | ), |
||
| 104 | 'format' => array( |
||
| 105 | 'name' => __( 'Format', 'podlove-subscribe-button' ), |
||
| 106 | 'options' => \PodloveSubscribeButton\Model\Button::$format |
||
| 107 | ), |
||
| 108 | 'autowidth' => array( |
||
| 109 | 'name' => __( 'Autowidth', 'podlove-subscribe-button' ), |
||
| 110 | 'options' => \PodloveSubscribeButton\Model\Button::$width |
||
| 111 | ) |
||
| 112 | ); |
||
| 113 | |||
| 114 | foreach ( $customize_options as $slug => $properties ) : ?> |
||
| 115 | <label for="<?php echo $this->get_field_id( $slug ); ?>"><?php echo $properties[ 'name' ]; ?></label> |
||
| 116 | <select class="widefat" id="<?php echo $this->get_field_id( $slug ); ?>" name="<?php echo $this->get_field_name( $slug ); ?>"> |
||
| 117 | <option value="default" <?php echo ( $$slug == 'default' ? 'selected="selected"' : '' ); ?>><?php printf( __( 'Default %s', 'podlove-subscribe-button' ), $properties[ 'name' ] ) ?></option> |
||
| 118 | <optgroup> |
||
| 119 | <?php foreach ( $properties[ 'options' ] as $property => $name ) : ?> |
||
| 120 | <option value="<?php echo $property; ?>" <?php echo ( $$slug == $property ? 'selected="selected"' : '' ); ?>><?php echo $name; ?></option> |
||
| 121 | <?php endforeach; ?> |
||
| 122 | </optgroup> |
||
| 123 | </select> |
||
| 124 | <?php endforeach; ?> |
||
| 125 | |||
| 126 | <label for="<?php echo $this->get_field_id( 'infotext' ); ?>"><?php _e( 'Description', 'podlove-subscribe-button' ); ?></label> |
||
| 127 | <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> |
||
| 128 | </p> |
||
| 143 |