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