| Conditions | 8 |
| Paths | 12 |
| Total Lines | 167 |
| Code Lines | 120 |
| 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 |
||
| 105 | public function options( $options, $pod ) { |
||
| 106 | |||
| 107 | // check if it's a post type pod and add fields for that. |
||
| 108 | if ( $pod['type'] === 'post_type' ) { |
||
| 109 | $options['pods-pfat'] = array( |
||
| 110 | 'pfat_enable' => array( |
||
| 111 | 'label' => __( 'Enable Automatic Pods Templates for this Pod?', 'pods' ), |
||
| 112 | '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' ), |
||
| 113 | 'type' => 'boolean', |
||
| 114 | 'default' => false, |
||
| 115 | 'dependency' => true, |
||
| 116 | 'boolean_yes_label' => '', |
||
| 117 | ), |
||
| 118 | 'pfat_run_outside_loop' => array( |
||
| 119 | 'label' => __( 'Execute Auto Template outside of the WordPress loop? (advanced)', 'pods' ), |
||
| 120 | 'help' => __( 'When enabled, the template will be executed whenever the specified filter is called.', 'pods' ), |
||
| 121 | 'type' => 'boolean', |
||
| 122 | 'default' => false, |
||
| 123 | 'depends-on' => array( 'pfat_enable' => true ), |
||
| 124 | 'boolean_yes_label' => '', |
||
| 125 | ), |
||
| 126 | 'pfat_single' => array( |
||
| 127 | 'label' => __( 'Single item view template', 'pods' ), |
||
| 128 | 'help' => __( 'Name of Pods template to use for single item view.', 'pods' ), |
||
| 129 | 'type' => 'text', |
||
| 130 | 'default' => false, |
||
| 131 | 'depends-on' => array( 'pfat_enable' => true ), |
||
| 132 | ), |
||
| 133 | 'pfat_append_single' => array( |
||
| 134 | 'label' => __( 'Single Template Location', 'pods' ), |
||
| 135 | 'help' => __( 'Whether the template will go before, after or in place of the post content.', 'pods' ), |
||
| 136 | 'depends-on' => array( 'pfat_enable' => true ), |
||
| 137 | ), |
||
| 138 | 'pfat_filter_single' => array( |
||
| 139 | 'label' => __( 'Single Template Filter', 'pods' ), |
||
| 140 | 'help' => __( 'Which filter to use for single views.', 'pods' ), |
||
| 141 | 'default' => 'the_content', |
||
| 142 | 'type' => 'text', |
||
| 143 | 'depends-on' => array( 'pfat_enable' => true ), |
||
| 144 | ), |
||
| 145 | 'pfat_archive' => array( |
||
| 146 | 'label' => __( 'Archive view template', 'pods' ), |
||
| 147 | 'help' => __( 'Name of Pods template to use for use in this Pods archive pages.', 'pods' ), |
||
| 148 | 'type' => 'text', |
||
| 149 | 'default' => false, |
||
| 150 | 'depends-on' => array( 'pfat_enable' => true ), |
||
| 151 | ), |
||
| 152 | 'pfat_append_archive' => array( |
||
| 153 | 'label' => __( 'Archive Template Location', 'pods' ), |
||
| 154 | 'help' => __( 'Whether the template will go before, after or in place of the post content.', 'pods' ), |
||
| 155 | 'depends-on' => array( 'pfat_enable' => true ), |
||
| 156 | ), |
||
| 157 | 'pfat_filter_archive' => array( |
||
| 158 | 'label' => __( 'Archive Template Filter', 'pods' ), |
||
| 159 | 'help' => __( 'Which filter to use for archives.', 'pods' ), |
||
| 160 | 'default' => 'the_content', |
||
| 161 | 'type' => 'text', |
||
| 162 | 'depends-on' => array( 'pfat_enable' => true ), |
||
| 163 | ), |
||
| 164 | ); |
||
| 165 | }//end if |
||
| 166 | |||
| 167 | // check if it's a taxonomy Pod, if so add fields for that |
||
| 168 | if ( $pod['type'] === 'taxonomy' ) { |
||
| 169 | $options['pods-pfat'] = array( |
||
| 170 | 'pfat_enable' => array( |
||
| 171 | 'label' => __( 'Enable Automatic Pods Templates for this Taxonomy Pod?', 'pods' ), |
||
| 172 | 'help' => __( 'When enabled you can specify the names of a Pods Template to be used to display information about this taxonomy and/or posts in this taxonomy in the front-end.', 'pods' ), |
||
| 173 | 'type' => 'boolean', |
||
| 174 | 'default' => false, |
||
| 175 | 'dependency' => true, |
||
| 176 | 'boolean_yes_label' => '', |
||
| 177 | ), |
||
| 178 | 'pfat_run_outside_loop' => array( |
||
| 179 | 'label' => __( 'Execute Auto Template outside of the WordPress loop? (advanced)', 'pods' ), |
||
| 180 | 'help' => __( 'When enabled, the template will be executed whenever the specified filter is called.', 'pods' ), |
||
| 181 | 'type' => 'boolean', |
||
| 182 | 'default' => false, |
||
| 183 | 'depends-on' => array( 'pfat_enable' => true ), |
||
| 184 | 'boolean_yes_label' => '', |
||
| 185 | ), |
||
| 186 | 'pfat_single' => array( |
||
| 187 | 'label' => __( 'Taxonomy Template', 'pods' ), |
||
| 188 | 'help' => __( 'Name of Pods template to use to present this taxonomy object itself.', 'pods' ), |
||
| 189 | 'type' => 'text', |
||
| 190 | 'default' => false, |
||
| 191 | 'depends-on' => array( 'pfat_enable' => true ), |
||
| 192 | ), |
||
| 193 | 'pfat_append_single' => array( |
||
| 194 | 'label' => __( 'Template Location', 'pods' ), |
||
| 195 | 'help' => __( 'Whether the template will go before, after or in place of the post content.', 'pods' ), |
||
| 196 | 'depends-on' => array( 'pfat_enable' => true ), |
||
| 197 | ), |
||
| 198 | 'pfat_filter_single' => array( |
||
| 199 | 'label' => __( 'Taxonomy Template Filter', 'pods' ), |
||
| 200 | 'help' => __( 'Which filter to use for taxonomy view.', 'pods' ), |
||
| 201 | 'default' => 'get_the_archive_description', |
||
| 202 | 'type' => 'text', |
||
| 203 | 'depends-on' => array( 'pfat_enable' => true ), |
||
| 204 | ), |
||
| 205 | 'pfat_archive' => array( |
||
| 206 | 'label' => __( 'Taxonomy Archive Template', 'pods' ), |
||
| 207 | 'help' => __( 'Name of Pods template to use for posts in this taxonomy.', 'pods' ), |
||
| 208 | 'type' => 'text', |
||
| 209 | 'default' => false, |
||
| 210 | 'depends-on' => array( 'pfat_enable' => true ), |
||
| 211 | ), |
||
| 212 | 'pfat_append_archive' => array( |
||
| 213 | 'label' => __( 'Archive Template Location', 'pods' ), |
||
| 214 | 'help' => __( 'Whether the template will go before, after or in place of the post content.', 'pods' ), |
||
| 215 | 'depends-on' => array( 'pfat_enable' => true ), |
||
| 216 | ), |
||
| 217 | 'pfat_filter_archive' => array( |
||
| 218 | 'label' => __( 'Archive Template Filter', 'pods' ), |
||
| 219 | 'help' => __( 'Which filter to use for archives.', 'pods' ), |
||
| 220 | 'default' => 'the_content', |
||
| 221 | 'type' => 'text', |
||
| 222 | 'depends-on' => array( 'pfat_enable' => true ), |
||
| 223 | ), |
||
| 224 | ); |
||
| 225 | }//end if |
||
| 226 | |||
| 227 | if ( isset( $options['pods-pfat'] ) ) { |
||
| 228 | |||
| 229 | // field options pick values |
||
| 230 | $pick = array( |
||
| 231 | 'type' => 'pick', |
||
| 232 | 'pick_format_type' => 'single', |
||
| 233 | 'pick_format_single' => 'dropdown', |
||
| 234 | 'default' => 'true', |
||
| 235 | ); |
||
| 236 | |||
| 237 | // get template titles |
||
| 238 | $titles = $this->get_template_titles(); |
||
| 239 | |||
| 240 | if ( ! empty( $titles ) ) { |
||
| 241 | foreach ( $pick as $k => $v ) { |
||
| 242 | $options['pods-pfat']['pfat_single'][ $k ] = $v; |
||
| 243 | |||
| 244 | $options['pods-pfat']['pfat_archive'][ $k ] = $v; |
||
| 245 | |||
| 246 | } |
||
| 247 | |||
| 248 | $options['pods-pfat']['pfat_archive']['data'] = array( null => __( 'No Archive view template', 'pods' ) ) + ( array_combine( $this->get_template_titles(), $this->get_template_titles() ) ); |
||
| 249 | $options['pods-pfat']['pfat_single']['data'] = array( null => __( 'No view template', 'pods' ) ) + array_combine( $this->get_template_titles(), $this->get_template_titles() ); |
||
| 250 | } |
||
| 251 | |||
| 252 | // Add data to $pick for template location |
||
| 253 | unset( $pick['data'] ); |
||
| 254 | $location_data = array( |
||
| 255 | 'append' => __( 'After', 'pods' ), |
||
| 256 | 'prepend' => __( 'Before', 'pods' ), |
||
| 257 | 'replace' => __( 'Replace', 'pods' ), |
||
| 258 | ); |
||
| 259 | $pick['data'] = $location_data; |
||
| 260 | |||
| 261 | // add location options to fields without type set. |
||
| 262 | foreach ( $options['pods-pfat'] as $k => $option ) { |
||
| 263 | if ( ! isset( $option['type'] ) ) { |
||
| 264 | $options['pods-pfat'][ $k ] = array_merge( $option, $pick ); |
||
| 265 | } |
||
| 266 | } |
||
| 267 | }//end if |
||
| 268 | |||
| 269 | return $options; |
||
| 270 | |||
| 271 | } |
||
| 272 | |||
| 417 |
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.