| Conditions | 4 |
| Paths | 8 |
| Total Lines | 190 |
| Code Lines | 139 |
| 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 |
||
| 203 | public function details_metaboxes() { |
||
| 204 | $cmb = new_cmb2_box( array( |
||
| 205 | 'id' => $this->slug . '_shopping_list_metabox', |
||
| 206 | 'title' => __( 'Shopping List', 'lsx-health-plan' ), |
||
| 207 | 'object_types' => array( $this->slug ), // Post type |
||
| 208 | 'context' => 'normal', |
||
| 209 | 'priority' => 'high', |
||
| 210 | 'show_names' => true, |
||
| 211 | ) ); |
||
| 212 | $cmb->add_field( array( |
||
| 213 | 'name' => __( 'Shopping List', 'lsx-health-plan' ), |
||
| 214 | 'desc' => __( 'Connect the shopping list page that applies to this meal by entering the name of the page in the field provided.' ), |
||
| 215 | 'id' => $this->slug . '_shopping_list', |
||
| 216 | 'type' => 'post_search_ajax', |
||
| 217 | // Optional : |
||
| 218 | 'limit' => 1, // Limit selection to X items only (default 1) |
||
| 219 | 'sortable' => true, // Allow selected items to be sortable (default false) |
||
| 220 | 'query_args' => array( |
||
| 221 | 'post_type' => array( 'page' ), |
||
| 222 | 'post_status' => array( 'publish' ), |
||
| 223 | 'posts_per_page' => -1, |
||
| 224 | ), |
||
| 225 | ) ); |
||
| 226 | $cmb = new_cmb2_box( array( |
||
| 227 | 'id' => $this->slug . '_details_metabox', |
||
| 228 | 'title' => __( 'Meal Details', 'lsx-health-plan' ), |
||
| 229 | 'object_types' => array( $this->slug ), // Post type |
||
| 230 | 'context' => 'normal', |
||
| 231 | 'priority' => 'high', |
||
| 232 | 'show_names' => true, |
||
| 233 | ) ); |
||
| 234 | |||
| 235 | $cmb->add_field( array( |
||
| 236 | 'name' => __( 'Meal Short Description', 'lsx-health-plan' ), |
||
| 237 | 'id' => $this->slug . '_short_description', |
||
| 238 | 'type' => 'textarea_small', |
||
| 239 | 'desc' => __( 'Add a small description for this meal (optional)', 'lsx-health-plan' ), |
||
| 240 | ) ); |
||
| 241 | |||
| 242 | $cmb->add_field( array( |
||
| 243 | 'name' => __( 'Pre Breakfast Snack', 'lsx-health-plan' ), |
||
| 244 | 'id' => $this->slug . '_pre_breakfast_snack', |
||
| 245 | 'type' => 'wysiwyg', |
||
| 246 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
| 247 | 'options' => array( |
||
| 248 | 'textarea_rows' => 5, |
||
| 249 | ), |
||
| 250 | ) ); |
||
| 251 | $cmb->add_field( array( |
||
| 252 | 'name' => __( 'Breakfast', 'lsx-health-plan' ), |
||
| 253 | 'id' => $this->slug . '_breakfast', |
||
| 254 | 'type' => 'wysiwyg', |
||
| 255 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
| 256 | 'options' => array( |
||
| 257 | 'textarea_rows' => 5, |
||
| 258 | ), |
||
| 259 | ) ); |
||
| 260 | |||
| 261 | $cmb->add_field( |
||
| 262 | array( |
||
| 263 | 'name' => __( 'Post Breakfast Snack', 'lsx-health-plan' ), |
||
| 264 | 'id' => $this->slug . '_breakfast_snack', |
||
| 265 | 'type' => 'wysiwyg', |
||
| 266 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
| 267 | 'options' => array( |
||
| 268 | 'textarea_rows' => 5, |
||
| 269 | ), |
||
| 270 | ) |
||
| 271 | ); |
||
| 272 | |||
| 273 | if ( post_type_exists( 'recipe' ) ) { |
||
| 274 | $cmb->add_field( |
||
| 275 | array( |
||
| 276 | 'name' => __( 'Breakfast Recipes', 'lsx-health-plan' ), |
||
| 277 | 'desc' => __( 'Connect additional recipes options for breakfast.', 'lsx-health-plan' ), |
||
| 278 | 'id' => 'breakfast_recipes', |
||
| 279 | 'type' => 'post_search_ajax', |
||
| 280 | // Optional : |
||
| 281 | 'limit' => 15, // Limit selection to X items only (default 1) |
||
| 282 | 'sortable' => true, // Allow selected items to be sortable (default false) |
||
| 283 | 'query_args' => array( |
||
| 284 | 'post_type' => array( 'recipe' ), |
||
| 285 | 'post_status' => array( 'publish' ), |
||
| 286 | 'posts_per_page' => -1, |
||
| 287 | ), |
||
| 288 | ) |
||
| 289 | ); |
||
| 290 | } |
||
| 291 | |||
| 292 | $cmb->add_field( |
||
| 293 | array( |
||
| 294 | 'name' => __( 'Pre Lunch Snack', 'lsx-health-plan' ), |
||
| 295 | 'id' => $this->slug . '_pre_lunch_snack', |
||
| 296 | 'type' => 'wysiwyg', |
||
| 297 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
| 298 | 'options' => array( |
||
| 299 | 'textarea_rows' => 5, |
||
| 300 | ), |
||
| 301 | ) |
||
| 302 | ); |
||
| 303 | $cmb->add_field( |
||
| 304 | array( |
||
| 305 | 'name' => __( 'Lunch', 'lsx-health-plan' ), |
||
| 306 | 'id' => $this->slug . '_lunch', |
||
| 307 | 'type' => 'wysiwyg', |
||
| 308 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
| 309 | 'options' => array( |
||
| 310 | 'textarea_rows' => 5, |
||
| 311 | ), |
||
| 312 | ) |
||
| 313 | ); |
||
| 314 | $cmb->add_field( |
||
| 315 | array( |
||
| 316 | 'name' => __( 'Post Lunch Snack', 'lsx-health-plan' ), |
||
| 317 | 'id' => $this->slug . '_lunch_snack', |
||
| 318 | 'type' => 'wysiwyg', |
||
| 319 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
| 320 | 'options' => array( |
||
| 321 | 'textarea_rows' => 5, |
||
| 322 | ), |
||
| 323 | ) |
||
| 324 | ); |
||
| 325 | |||
| 326 | if ( post_type_exists( 'recipe' ) ) { |
||
| 327 | $cmb->add_field( |
||
| 328 | array( |
||
| 329 | 'name' => __( 'Lunch Recipes', 'lsx-health-plan' ), |
||
| 330 | 'desc' => __( 'Connect additional recipes options for lunch.', 'lsx-health-plan' ), |
||
| 331 | 'id' => 'lunch_recipes', |
||
| 332 | 'type' => 'post_search_ajax', |
||
| 333 | // Optional : |
||
| 334 | 'limit' => 15, // Limit selection to X items only (default 1) |
||
| 335 | 'sortable' => true, // Allow selected items to be sortable (default false) |
||
| 336 | 'query_args' => array( |
||
| 337 | 'post_type' => array( 'recipe' ), |
||
| 338 | 'post_status' => array( 'publish' ), |
||
| 339 | 'posts_per_page' => -1, |
||
| 340 | ), |
||
| 341 | ) |
||
| 342 | ); |
||
| 343 | } |
||
| 344 | |||
| 345 | $cmb->add_field( |
||
| 346 | array( |
||
| 347 | 'name' => __( 'Pre Dinner Snack', 'lsx-health-plan' ), |
||
| 348 | 'id' => $this->slug . '_pre_dinner_snack', |
||
| 349 | 'type' => 'wysiwyg', |
||
| 350 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
| 351 | 'options' => array( |
||
| 352 | 'textarea_rows' => 5, |
||
| 353 | ), |
||
| 354 | ) |
||
| 355 | ); |
||
| 356 | $cmb->add_field( |
||
| 357 | array( |
||
| 358 | 'name' => __( 'Dinner', 'lsx-health-plan' ), |
||
| 359 | 'id' => $this->slug . '_dinner', |
||
| 360 | 'type' => 'wysiwyg', |
||
| 361 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
| 362 | 'options' => array( |
||
| 363 | 'textarea_rows' => 5, |
||
| 364 | ), |
||
| 365 | ) |
||
| 366 | ); |
||
| 367 | $cmb->add_field( |
||
| 368 | array( |
||
| 369 | 'name' => __( 'Post Dinner Snack', 'lsx-health-plan' ), |
||
| 370 | 'id' => $this->slug . '_dinner_snack', |
||
| 371 | 'type' => 'wysiwyg', |
||
| 372 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
| 373 | 'options' => array( |
||
| 374 | 'textarea_rows' => 5, |
||
| 375 | ), |
||
| 376 | ) |
||
| 377 | ); |
||
| 378 | |||
| 379 | if ( post_type_exists( 'recipe' ) ) { |
||
| 380 | $cmb->add_field( |
||
| 381 | array( |
||
| 382 | 'name' => __( 'Dinner Recipes', 'lsx-health-plan' ), |
||
| 383 | 'desc' => __( 'Connect additional recipes options for dinner.', 'lsx-health-plan' ), |
||
| 384 | 'id' => 'dinner_recipes', |
||
| 385 | 'type' => 'post_search_ajax', |
||
| 386 | // Optional : |
||
| 387 | 'limit' => 15, // Limit selection to X items only (default 1) |
||
| 388 | 'sortable' => true, // Allow selected items to be sortable (default false) |
||
| 389 | 'query_args' => array( |
||
| 390 | 'post_type' => array( 'recipe' ), |
||
| 391 | 'post_status' => array( 'publish' ), |
||
| 392 | 'posts_per_page' => -1, |
||
| 393 | ), |
||
| 410 |