Conditions | 9 |
Paths | 20 |
Total Lines | 117 |
Code Lines | 74 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | 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 |
||
109 | function options( $options, $pod ) { |
||
110 | //check if it's a post type pod and add fields for that. |
||
111 | if ( $pod['type'] === 'post_type' ) { |
||
112 | $options[ 'pods-pfat' ] = array ( |
||
113 | 'pfat_enable' => array ( |
||
114 | 'label' => __( 'Enable Automatic Pods Templates for this Pod?', 'pods' ), |
||
115 | 'help' => __( 'When enabled you can specify the names of Pods Templates to be used to display items in this Pod in the front-end.', 'pods' ), |
||
116 | 'type' => 'boolean', |
||
117 | 'default' => false, |
||
118 | 'dependency' => true, |
||
119 | 'boolean_yes_label' => '' |
||
120 | ), |
||
121 | 'pfat_single' => array ( |
||
122 | 'label' => __( 'Single item view template', 'pods' ), |
||
123 | 'help' => __( 'Name of Pods template to use for single item view.', 'pods' ), |
||
124 | 'type' => 'text', |
||
125 | 'default' => false, |
||
126 | 'depends-on' => array ( 'pfat_enable' => true ) |
||
127 | ), |
||
128 | 'pfat_append_single' => array ( |
||
129 | 'label' => __( 'Single Template Location', 'pods' ), |
||
130 | 'help' => __( 'Whether the template will go before, after or in place of the post content.', 'pods' ), |
||
131 | 'depends-on' => array ( 'pfat_enable' => true ), |
||
132 | ), |
||
133 | 'pfat_archive' => array ( |
||
134 | 'label' => __( 'Archive view template', 'pods' ), |
||
135 | 'help' => __( 'Name of Pods template to use for use in this Pods archive pages.', 'pods' ), |
||
136 | 'type' => 'text', |
||
137 | 'default' => false, |
||
138 | 'depends-on' => array ( 'pfat_enable' => true ) |
||
139 | ), |
||
140 | 'pfat_append_archive' => array ( |
||
141 | 'label' => __( 'Archive Template Location', 'pods' ), |
||
142 | 'help' => __( 'Whether the template will go before, after or in place of the post content.', 'pods' ), |
||
143 | 'depends-on' => array ( 'pfat_enable' => true ), |
||
144 | ), |
||
145 | ); |
||
146 | } |
||
147 | |||
148 | //check if it's a taxonomy Pod, if so add fields for that |
||
149 | if ( $pod['type'] === 'taxonomy' ) { |
||
150 | $options[ 'pods-pfat' ] = array ( |
||
151 | 'pfat_enable' => array ( |
||
152 | 'label' => __( 'Enable Automatic Pods Templates for this Pod?', 'pods' ), |
||
153 | 'help' => __( 'When enabled you can specify the names of a Pods Template to be used to display items in this Pod in the front-end.', 'pods' ), |
||
154 | 'type' => 'boolean', |
||
155 | 'default' => false, |
||
156 | 'dependency' => true, |
||
157 | 'boolean_yes_label' => '' |
||
158 | ), |
||
159 | 'pfat_archive' => array ( |
||
160 | 'label' => __( 'Taxonomy Template', 'pods' ), |
||
161 | 'help' => __( 'Name of Pods template to use for this taxonomy.', 'pods' ), |
||
162 | 'type' => 'text', |
||
163 | 'default' => false, |
||
164 | 'depends-on' => array ( 'pfat_enable' => true ) |
||
165 | ), |
||
166 | 'pfat_append_archive' => array ( |
||
167 | 'label' => __( 'Template Location', 'pods' ), |
||
168 | 'help' => __( 'Whether the template will go before, after or in place of the post content.', 'pods' ), |
||
169 | 'depends-on' => array ( 'pfat_enable' => true ), |
||
170 | ), |
||
171 | ); |
||
172 | } |
||
173 | |||
174 | if ( isset( $options[ 'pods-pfat' ] ) ) { |
||
175 | |||
176 | //field options pick values |
||
177 | $pick = array ( |
||
178 | 'type' => 'pick', |
||
179 | 'pick_format_type' => 'single', |
||
180 | 'pick_format_single' => 'dropdown', |
||
181 | 'default' => 'true', |
||
182 | ); |
||
183 | |||
184 | //get template titles |
||
185 | $titles = $this->get_template_titles(); |
||
186 | |||
187 | if ( !empty( $titles ) ) { |
||
188 | foreach ( $pick as $k => $v ) { |
||
189 | $options[ 'pods-pfat' ][ 'pfat_single' ][ $k ] = $v; |
||
190 | |||
191 | $options[ 'pods-pfat' ][ 'pfat_archive' ][ $k ] = $v; |
||
192 | |||
193 | } |
||
194 | |||
195 | $options[ 'pods-pfat' ][ 'pfat_archive' ][ 'data' ] = array( null => __('No Archive view template', 'pods') ) + ( array_combine( $this->get_template_titles(), $this->get_template_titles() ) ); |
||
196 | $options[ 'pods-pfat' ][ 'pfat_single' ][ 'data' ] = array_combine( $this->get_template_titles(), $this->get_template_titles() ); |
||
197 | } |
||
198 | |||
199 | //Add data to $pick for template location |
||
200 | unset( $pick['data']); |
||
201 | $location_data = array ( |
||
202 | 'append' => __( 'After', 'pods' ), |
||
203 | 'prepend' => __( 'Before', 'pods' ), |
||
204 | 'replace' => __( 'Replace', 'pods' ), |
||
205 | ); |
||
206 | $pick['data'] = $location_data; |
||
207 | |||
208 | //add location options to fields without type set. |
||
209 | foreach ( $options[ 'pods-pfat' ] as $k => $option ) { |
||
210 | if ( !isset( $option[ 'type' ] ) ) { |
||
211 | $options[ 'pods-pfat' ][ $k ] = array_merge( $option, $pick ); |
||
212 | } |
||
213 | |||
214 | } |
||
215 | |||
216 | //remove single from taxonomy |
||
217 | if( 'taxonomy' === $pod['type'] ){ |
||
218 | unset( $options[ 'pods-pfat' ][ 'pfat_single' ] ); |
||
219 | } |
||
220 | |||
221 | } |
||
222 | |||
223 | return $options; |
||
224 | |||
225 | } |
||
226 | |||
375 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.