| 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 |
||
| 152 | public function details_metaboxes() { |
||
| 153 | $cmb = new_cmb2_box( array( |
||
| 154 | 'id' => $this->slug . '_shopping_list_metabox', |
||
| 155 | 'title' => __( 'Shopping List', 'lsx-health-plan' ), |
||
| 156 | 'object_types' => array( $this->slug ), // Post type |
||
| 157 | 'context' => 'normal', |
||
| 158 | 'priority' => 'high', |
||
| 159 | 'show_names' => true, |
||
| 160 | ) ); |
||
| 161 | $cmb->add_field( array( |
||
| 162 | 'name' => __( 'Shopping List', 'lsx-health-plan' ), |
||
| 163 | 'desc' => __( 'Connect the shopping list page that applies to this meal by entering the name of the page in the field provided.' ), |
||
| 164 | 'id' => $this->slug . '_shopping_list', |
||
| 165 | 'type' => 'post_search_ajax', |
||
| 166 | // Optional : |
||
| 167 | 'limit' => 1, // Limit selection to X items only (default 1) |
||
| 168 | 'sortable' => true, // Allow selected items to be sortable (default false) |
||
| 169 | 'query_args' => array( |
||
| 170 | 'post_type' => array( 'page' ), |
||
| 171 | 'post_status' => array( 'publish' ), |
||
| 172 | 'posts_per_page' => -1, |
||
| 173 | ), |
||
| 174 | ) ); |
||
| 175 | $cmb = new_cmb2_box( array( |
||
| 176 | 'id' => $this->slug . '_details_metabox', |
||
| 177 | 'title' => __( 'Meal Details', 'lsx-health-plan' ), |
||
| 178 | 'object_types' => array( $this->slug ), // Post type |
||
| 179 | 'context' => 'normal', |
||
| 180 | 'priority' => 'high', |
||
| 181 | 'show_names' => true, |
||
| 182 | ) ); |
||
| 183 | |||
| 184 | $cmb->add_field( array( |
||
| 185 | 'name' => __( 'Meal Short Description', 'lsx-health-plan' ), |
||
| 186 | 'id' => $this->slug . '_short_description', |
||
| 187 | 'type' => 'textarea_small', |
||
| 188 | 'desc' => __( 'Add a small description for this meal (optional)', 'lsx-health-plan' ), |
||
| 189 | ) ); |
||
| 190 | |||
| 191 | $cmb->add_field( array( |
||
| 192 | 'name' => __( 'Pre Breakfast Snack', 'lsx-health-plan' ), |
||
| 193 | 'id' => $this->slug . '_pre_breakfast_snack', |
||
| 194 | 'type' => 'wysiwyg', |
||
| 195 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
| 196 | 'options' => array( |
||
| 197 | 'textarea_rows' => 5, |
||
| 198 | ), |
||
| 199 | ) ); |
||
| 200 | $cmb->add_field( array( |
||
| 201 | 'name' => __( 'Breakfast', 'lsx-health-plan' ), |
||
| 202 | 'id' => $this->slug . '_breakfast', |
||
| 203 | 'type' => 'wysiwyg', |
||
| 204 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
| 205 | 'options' => array( |
||
| 206 | 'textarea_rows' => 5, |
||
| 207 | ), |
||
| 208 | ) ); |
||
| 209 | |||
| 210 | $cmb->add_field( |
||
| 211 | array( |
||
| 212 | 'name' => __( 'Post Breakfast Snack', 'lsx-health-plan' ), |
||
| 213 | 'id' => $this->slug . '_breakfast_snack', |
||
| 214 | 'type' => 'wysiwyg', |
||
| 215 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
| 216 | 'options' => array( |
||
| 217 | 'textarea_rows' => 5, |
||
| 218 | ), |
||
| 219 | ) |
||
| 220 | ); |
||
| 221 | |||
| 222 | if ( post_type_exists( 'recipe' ) ) { |
||
| 223 | $cmb->add_field( |
||
| 224 | array( |
||
| 225 | 'name' => __( 'Breakfast Recipes', 'lsx-health-plan' ), |
||
| 226 | 'desc' => __( 'Connect additional recipes options for breakfast.', 'lsx-health-plan' ), |
||
| 227 | 'id' => 'breakfast_recipes', |
||
| 228 | 'type' => 'post_search_ajax', |
||
| 229 | // Optional : |
||
| 230 | 'limit' => 15, // Limit selection to X items only (default 1) |
||
| 231 | 'sortable' => true, // Allow selected items to be sortable (default false) |
||
| 232 | 'query_args' => array( |
||
| 233 | 'post_type' => array( 'recipe' ), |
||
| 234 | 'post_status' => array( 'publish' ), |
||
| 235 | 'posts_per_page' => -1, |
||
| 236 | ), |
||
| 237 | ) |
||
| 238 | ); |
||
| 239 | } |
||
| 240 | |||
| 241 | $cmb->add_field( |
||
| 242 | array( |
||
| 243 | 'name' => __( 'Pre Lunch Snack', 'lsx-health-plan' ), |
||
| 244 | 'id' => $this->slug . '_pre_lunch_snack', |
||
| 245 | 'type' => 'wysiwyg', |
||
| 246 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
| 247 | 'options' => array( |
||
| 248 | 'textarea_rows' => 5, |
||
| 249 | ), |
||
| 250 | ) |
||
| 251 | ); |
||
| 252 | $cmb->add_field( |
||
| 253 | array( |
||
| 254 | 'name' => __( 'Lunch', 'lsx-health-plan' ), |
||
| 255 | 'id' => $this->slug . '_lunch', |
||
| 256 | 'type' => 'wysiwyg', |
||
| 257 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
| 258 | 'options' => array( |
||
| 259 | 'textarea_rows' => 5, |
||
| 260 | ), |
||
| 261 | ) |
||
| 262 | ); |
||
| 263 | $cmb->add_field( |
||
| 264 | array( |
||
| 265 | 'name' => __( 'Post Lunch Snack', 'lsx-health-plan' ), |
||
| 266 | 'id' => $this->slug . '_lunch_snack', |
||
| 267 | 'type' => 'wysiwyg', |
||
| 268 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
| 269 | 'options' => array( |
||
| 270 | 'textarea_rows' => 5, |
||
| 271 | ), |
||
| 272 | ) |
||
| 273 | ); |
||
| 274 | |||
| 275 | if ( post_type_exists( 'recipe' ) ) { |
||
| 276 | $cmb->add_field( |
||
| 277 | array( |
||
| 278 | 'name' => __( 'Lunch Recipes', 'lsx-health-plan' ), |
||
| 279 | 'desc' => __( 'Connect additional recipes options for lunch.', 'lsx-health-plan' ), |
||
| 280 | 'id' => 'lunch_recipes', |
||
| 281 | 'type' => 'post_search_ajax', |
||
| 282 | // Optional : |
||
| 283 | 'limit' => 15, // Limit selection to X items only (default 1) |
||
| 284 | 'sortable' => true, // Allow selected items to be sortable (default false) |
||
| 285 | 'query_args' => array( |
||
| 286 | 'post_type' => array( 'recipe' ), |
||
| 287 | 'post_status' => array( 'publish' ), |
||
| 288 | 'posts_per_page' => -1, |
||
| 289 | ), |
||
| 290 | ) |
||
| 291 | ); |
||
| 292 | } |
||
| 293 | |||
| 294 | $cmb->add_field( |
||
| 295 | array( |
||
| 296 | 'name' => __( 'Pre Dinner Snack', 'lsx-health-plan' ), |
||
| 297 | 'id' => $this->slug . '_pre_dinner_snack', |
||
| 298 | 'type' => 'wysiwyg', |
||
| 299 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
| 300 | 'options' => array( |
||
| 301 | 'textarea_rows' => 5, |
||
| 302 | ), |
||
| 303 | ) |
||
| 304 | ); |
||
| 305 | $cmb->add_field( |
||
| 306 | array( |
||
| 307 | 'name' => __( 'Dinner', 'lsx-health-plan' ), |
||
| 308 | 'id' => $this->slug . '_dinner', |
||
| 309 | 'type' => 'wysiwyg', |
||
| 310 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
| 311 | 'options' => array( |
||
| 312 | 'textarea_rows' => 5, |
||
| 313 | ), |
||
| 314 | ) |
||
| 315 | ); |
||
| 316 | $cmb->add_field( |
||
| 317 | array( |
||
| 318 | 'name' => __( 'Post Dinner Snack', 'lsx-health-plan' ), |
||
| 319 | 'id' => $this->slug . '_dinner_snack', |
||
| 320 | 'type' => 'wysiwyg', |
||
| 321 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
| 322 | 'options' => array( |
||
| 323 | 'textarea_rows' => 5, |
||
| 324 | ), |
||
| 325 | ) |
||
| 326 | ); |
||
| 327 | |||
| 328 | if ( post_type_exists( 'recipe' ) ) { |
||
| 329 | $cmb->add_field( |
||
| 330 | array( |
||
| 331 | 'name' => __( 'Dinner Recipes', 'lsx-health-plan' ), |
||
| 332 | 'desc' => __( 'Connect additional recipes options for dinner.', 'lsx-health-plan' ), |
||
| 333 | 'id' => 'dinner_recipes', |
||
| 334 | 'type' => 'post_search_ajax', |
||
| 335 | // Optional : |
||
| 336 | 'limit' => 15, // Limit selection to X items only (default 1) |
||
| 337 | 'sortable' => true, // Allow selected items to be sortable (default false) |
||
| 338 | 'query_args' => array( |
||
| 339 | 'post_type' => array( 'recipe' ), |
||
| 340 | 'post_status' => array( 'publish' ), |
||
| 341 | 'posts_per_page' => -1, |
||
| 342 | ), |
||
| 348 |