Conditions | 6 |
Paths | 6 |
Total Lines | 59 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
107 | public function add_fields() { |
||
108 | |||
109 | $fields = array(); |
||
110 | $feed_types = $this->calendar_types; |
||
111 | $this->values = get_option( 'simple-calendar_' . $this->option_group . '_' . $this->id ); |
||
112 | |||
113 | foreach ( $this->sections as $section => $contents ) : |
||
114 | |||
115 | if ( 'general' == $section ) { |
||
116 | |||
117 | $options = array(); |
||
118 | $post_types = get_post_types( |
||
119 | array( |
||
120 | 'public' => false, |
||
121 | 'publicly_queriable' => false, |
||
122 | 'show_ui' => false, |
||
123 | ), |
||
124 | 'objects', |
||
125 | 'not' |
||
126 | ); |
||
127 | unset( $post_types['attachment'] ); |
||
128 | unset( $post_types['calendar'] ); |
||
129 | unset( $post_types['gce_feed'] ); |
||
130 | foreach ( $post_types as $slug => $post_type ) { |
||
131 | $options[ $slug ] = $post_type->label; |
||
132 | } |
||
133 | asort( $options ); |
||
134 | |||
135 | $fields[ $section ][] = array( |
||
136 | 'type' => 'select', |
||
137 | 'multiselect' => 'multiselect', |
||
138 | 'enhanced' => 'enhanced', |
||
139 | 'title' => __( 'Attach Calendars', 'google-calendar-events' ), |
||
140 | 'tooltip' => __( 'You can choose on which content types to add the ability to attach calendars.', 'google-calendar-events' ), |
||
141 | 'name' => 'simple-calendar_' . $this->option_group . '_' . $this->id . '[' . $section . '][attach_calendars_posts]', |
||
142 | 'id' => 'simple-calendar-' . $this->option_group . '-' . $this->id . '-attach-calendars-posts', |
||
143 | 'value' => $this->get_option_value( $section, 'attach_calendars_posts' ), |
||
144 | 'default' => 'post,page', |
||
145 | 'options' => $options, |
||
146 | ); |
||
147 | |||
148 | } elseif ( isset( $feed_types[ $section ]['fields'] ) ) { |
||
149 | |||
150 | foreach ( $feed_types[ $section ]['fields'] as $key => $args ) { |
||
151 | |||
152 | $fields[ $section ][] = array_merge( $args, array( |
||
153 | 'name' => 'simple-calendar_' . $this->option_group . '_' . $this->id . '[' . $section . '][' . $key . ']', |
||
154 | 'id' => 'simple-calendar-' . $this->option_group . '-' . $this->id . '-' . $key, |
||
155 | 'value' => $this->get_option_value( $section, $key ) |
||
156 | ) ); |
||
157 | |||
158 | } |
||
159 | |||
160 | } |
||
161 | |||
162 | endforeach; |
||
163 | |||
164 | return apply_filters( 'simcal_add_' . $this->option_group . '_' . $this->id . '_fields', $fields ); |
||
165 | } |
||
166 | |||
168 |