| Conditions | 1 |
| Paths | 1 |
| Total Lines | 177 |
| Code Lines | 111 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 424 | protected function setupUpdateOperation() |
||
| 425 | { |
||
| 426 | CRUD::addFields([ |
||
| 427 | [ |
||
| 428 | // RYTHM |
||
| 429 | 'label' => __('Partnership'), |
||
| 430 | 'type' => 'select', |
||
| 431 | 'name' => 'partner_id', |
||
| 432 | 'entity' => 'partner', |
||
| 433 | 'attribute' => 'name', |
||
| 434 | 'model' => Partner::class, |
||
| 435 | 'tab' => __('Course info'), |
||
| 436 | ], |
||
| 437 | |||
| 438 | [ |
||
| 439 | // RYTHM |
||
| 440 | 'label' => __('Rhythm'), |
||
| 441 | 'type' => 'select', |
||
| 442 | 'name' => 'rhythm_id', |
||
| 443 | 'entity' => 'rhythm', |
||
| 444 | 'attribute' => 'name', |
||
| 445 | 'model' => Rhythm::class, |
||
| 446 | 'tab' => __('Course info'), |
||
| 447 | ], |
||
| 448 | |||
| 449 | [ |
||
| 450 | // LEVEL |
||
| 451 | 'label' => __('Level'), |
||
| 452 | 'type' => 'select', |
||
| 453 | 'name' => 'level_id', |
||
| 454 | 'entity' => 'level', |
||
| 455 | 'attribute' => 'name', |
||
| 456 | 'model' => Level::class, |
||
| 457 | 'tab' => __('Course info'), |
||
| 458 | ], |
||
| 459 | |||
| 460 | [ |
||
| 461 | 'name' => 'name', |
||
| 462 | 'label' => __('Name'), |
||
| 463 | 'tab' => __('Course info'), |
||
| 464 | ], |
||
| 465 | |||
| 466 | [ |
||
| 467 | 'name' => 'volume', |
||
| 468 | 'label' => __('Volume'), |
||
| 469 | 'suffix' => 'h', |
||
| 470 | 'tab' => __('Course info'), |
||
| 471 | ], |
||
| 472 | |||
| 473 | [ |
||
| 474 | 'name' => 'hourly_price', |
||
| 475 | 'label' => __('Hourly Price'), |
||
| 476 | 'prefix' => '$', |
||
| 477 | 'tab' => __('Course info'), |
||
| 478 | ], |
||
| 479 | |||
| 480 | [ |
||
| 481 | // TEACHER |
||
| 482 | 'label' => __('Teacher'), |
||
| 483 | 'type' => 'select', |
||
| 484 | 'name' => 'teacher_id', |
||
| 485 | 'entity' => 'teacher', |
||
| 486 | 'attribute' => 'name', |
||
| 487 | 'model' => Teacher::class, |
||
| 488 | 'tab' => __('Course info'), |
||
| 489 | ], |
||
| 490 | |||
| 491 | [ |
||
| 492 | // ROOM |
||
| 493 | 'label' => __('Room'), |
||
| 494 | 'type' => 'select', |
||
| 495 | 'name' => 'room_id', |
||
| 496 | 'entity' => 'room', |
||
| 497 | 'attribute' => 'name', |
||
| 498 | 'model' => Room::class, |
||
| 499 | 'tab' => __('Course info'), |
||
| 500 | ], |
||
| 501 | |||
| 502 | [ |
||
| 503 | // RYTHM |
||
| 504 | 'label' => __('Campus'), |
||
| 505 | 'type' => 'hidden', |
||
| 506 | 'name' => 'campus_id', |
||
| 507 | 'value' => 2, |
||
| 508 | 'tab' => __('Course info'), |
||
| 509 | ], |
||
| 510 | |||
| 511 | [ |
||
| 512 | 'name' => 'price', |
||
| 513 | 'type' => 'hidden', |
||
| 514 | 'value' => 0, |
||
| 515 | 'tab' => __('Course info'), |
||
| 516 | ], |
||
| 517 | |||
| 518 | [ |
||
| 519 | // PERIOD |
||
| 520 | 'label' => __('Period'), |
||
| 521 | 'type' => 'select', |
||
| 522 | 'name' => 'period_id', |
||
| 523 | 'entity' => 'period', |
||
| 524 | 'attribute' => 'name', |
||
| 525 | 'model' => Period::class, |
||
| 526 | 'tab' => __('Schedule'), |
||
| 527 | 'default' => Period::get_enrollments_period()->id, |
||
| 528 | ], |
||
| 529 | |||
| 530 | [ |
||
| 531 | 'name' => 'start_date', |
||
| 532 | 'label' => __('Start Date'), |
||
| 533 | 'type' => 'date', |
||
| 534 | 'tab' => __('Schedule'), |
||
| 535 | 'default' => Period::get_enrollments_period()->start, |
||
| 536 | ], |
||
| 537 | |||
| 538 | [ |
||
| 539 | 'name' => 'end_date', |
||
| 540 | 'label' => __('End Date'), |
||
| 541 | 'type' => 'date', |
||
| 542 | 'tab' => __('Schedule'), |
||
| 543 | 'default' => Period::get_enrollments_period()->end, |
||
| 544 | ], |
||
| 545 | |||
| 546 | [ |
||
| 547 | 'name' => 'head_count', |
||
| 548 | 'label' => __('Head Count'), |
||
| 549 | 'type' => 'number', |
||
| 550 | 'tab' => __('Course info'), |
||
| 551 | ], |
||
| 552 | |||
| 553 | [ |
||
| 554 | 'name' => 'new_students', |
||
| 555 | 'label' => __('Students to count in year total'), |
||
| 556 | 'type' => 'number', |
||
| 557 | 'tab' => __('Course info'), |
||
| 558 | ], |
||
| 559 | |||
| 560 | [ // repeatable |
||
| 561 | 'name' => 'times', |
||
| 562 | 'label' => __('Course Schedule'), |
||
| 563 | 'type' => 'repeatable', |
||
| 564 | 'fields' => [ |
||
| 565 | [ |
||
| 566 | 'name' => 'day', |
||
| 567 | 'label' => __('Day'), |
||
| 568 | 'type' => 'select_from_array', |
||
| 569 | 'options' => [ |
||
| 570 | 0 => __('Sunday'), |
||
| 571 | 1 => __('Monday'), |
||
| 572 | 2 => __('Tuesday'), |
||
| 573 | 3 => __('Wednesday'), |
||
| 574 | 4 => __('Thursday'), |
||
| 575 | 5 => __('Friday'), |
||
| 576 | 6 => __('Saturday'), |
||
| 577 | ], |
||
| 578 | 'allows_null' => false, |
||
| 579 | 'default' => 1, |
||
| 580 | 'wrapper' => ['class' => 'form-group col-md-4'], |
||
| 581 | ], |
||
| 582 | [ |
||
| 583 | 'name' => 'start', |
||
| 584 | 'type' => 'time', |
||
| 585 | 'label' => __('Start'), |
||
| 586 | 'wrapper' => ['class' => 'form-group col-md-4'], |
||
| 587 | ], |
||
| 588 | [ |
||
| 589 | 'name' => 'end', |
||
| 590 | 'type' => 'time', |
||
| 591 | 'label' => __('End'), |
||
| 592 | 'wrapper' => ['class' => 'form-group col-md-4'], |
||
| 593 | ], |
||
| 594 | ], |
||
| 595 | 'init_rows' => 0, |
||
| 596 | 'tab' => __('Schedule'), |
||
| 597 | ], |
||
| 598 | ]); |
||
| 599 | |||
| 600 | CRUD::setValidation(UpdateRequest::class); |
||
| 601 | } |
||
| 632 |