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