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