| Conditions | 1 |
| Paths | 1 |
| Total Lines | 63 |
| Code Lines | 47 |
| 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 |
||
| 19 | public function setup(): void |
||
| 20 | { |
||
| 21 | // Eloquent model to associate with this collection of views and controller actions. |
||
| 22 | $this->crud->setModel('App\Models\Lookup\JobPosterStatusTransition'); |
||
| 23 | // Custom backpack route. |
||
| 24 | $this->crud->setRoute('admin/job-poster-status-transition'); |
||
| 25 | // Custom strings to display within the backpack UI. |
||
| 26 | $this->crud->setEntityNameStrings('job status transition', 'job status transitions'); |
||
| 27 | |||
| 28 | $this->crud->operation(['update'], function () { |
||
| 29 | $this->crud->addField([ |
||
| 30 | 'name' => 'key', |
||
| 31 | 'type' => 'text', |
||
| 32 | 'label' => 'Key', |
||
| 33 | 'attributes' => ['disabled' => 'disabled'] |
||
| 34 | ]); |
||
| 35 | |||
| 36 | $this->crud->addField([ |
||
| 37 | 'name' => 'name', |
||
| 38 | 'type' => 'text', |
||
| 39 | 'label' => 'Name', |
||
| 40 | 'limit' => 120, |
||
| 41 | ]); |
||
| 42 | |||
| 43 | $this->crud->addField([ // Select |
||
| 44 | 'label' => 'Owner User Role', |
||
| 45 | 'type' => 'select', |
||
| 46 | 'name' => 'owner_user_role_id', // the db column for the foreign key |
||
| 47 | 'entity' => 'owner_user_role', // the method that defines the relationship in your Model |
||
| 48 | 'attribute' => 'key', // foreign key attribute that is shown to user |
||
| 49 | 'model' => \App\Models\UserRole::class, // foreign key model |
||
| 50 | 'attributes' => ['disabled' => 'disabled'] |
||
| 51 | ]); |
||
| 52 | |||
| 53 | $this->crud->addField([ // Select |
||
| 54 | 'label' => 'From Status', |
||
| 55 | 'type' => 'select', |
||
| 56 | 'name' => 'from_job_poster_status_id', // the db column for the foreign key |
||
| 57 | 'entity' => 'from', // the method that defines the relationship in your Model |
||
| 58 | 'attribute' => 'key', // foreign key attribute that is shown to user |
||
| 59 | 'model' => \App\Models\Lookup\JobPosterStatus::class, // foreign key model |
||
| 60 | 'attributes' => ['disabled' => 'disabled'] |
||
| 61 | ]); |
||
| 62 | |||
| 63 | $this->crud->addField([ // Select |
||
| 64 | 'label' => 'To Status', |
||
| 65 | 'type' => 'select', |
||
| 66 | 'name' => 'to_job_poster_status_id', // the db column for the foreign key |
||
| 67 | 'entity' => 'to', // the method that defines the relationship in your Model |
||
| 68 | 'attribute' => 'key', // foreign key attribute that is shown to user |
||
| 69 | 'model' => \App\Models\Lookup\JobPosterStatus::class, // foreign key model |
||
| 70 | 'attributes' => ['disabled' => 'disabled'] |
||
| 71 | ]); |
||
| 72 | |||
| 73 | $this->crud->addField([ |
||
| 74 | 'name' => 'button_style', |
||
| 75 | 'label' => 'Button Style', |
||
| 76 | 'type' => 'select_from_array', |
||
| 77 | 'options' => ['default' => 'default', 'stop' => 'stop', 'go' => 'go'], |
||
| 78 | 'allows_null' => false, |
||
| 79 | 'default' => 'default', |
||
| 80 | 'fake' => true, // show the field, but don’t store it in the database column above |
||
| 81 | 'store_in' => 'metadata' // [optional] the database column name where you want the fake fields to ACTUALLY be stored as a JSON array |
||
| 82 | ]); |
||
| 136 |