| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 29 |
| 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 |
||
| 13 | protected function defineFieldDefinitions(): void |
||
| 14 | { |
||
| 15 | // add dynamic rules at $this->processFieldDefinitions() |
||
| 16 | $this->fieldDefinitions = [ |
||
| 17 | 'id' => $this->getIdField(), |
||
| 18 | |||
| 19 | 'username' => $this->getField( |
||
| 20 | __('username'), |
||
| 21 | [ |
||
| 22 | 'rules' => [ |
||
| 23 | 'required', |
||
| 24 | ['lengthMin', 3] |
||
| 25 | ], |
||
| 26 | 'display_in_list' => true |
||
| 27 | ] |
||
| 28 | ), |
||
| 29 | |||
| 30 | 'password' => $this->getField( |
||
| 31 | __('password'), |
||
| 32 | [ |
||
| 33 | 'type' => 'password', |
||
| 34 | 'rules' => [ |
||
| 35 | 'required', |
||
| 36 | ['lengthMin', 8] |
||
| 37 | ], |
||
| 38 | 'filter' => FILTER_UNSAFE_RAW, |
||
| 39 | ] |
||
| 40 | ), |
||
| 41 | |||
| 42 | 'role' => $this->getField( |
||
| 43 | __('role'), |
||
| 44 | [ |
||
| 45 | 'type' => 'select', |
||
| 46 | 'options' => [ |
||
| 47 | 'editor' => __('editor'), |
||
| 48 | 'admin' => __('admin'), |
||
| 49 | ], |
||
| 50 | 'rules' => [ |
||
| 51 | 'required', |
||
| 52 | ], |
||
| 53 | 'attributes' => [ |
||
| 54 | 'class' => 'form-control form-select' |
||
| 55 | ], |
||
| 56 | 'display_in_list' => true |
||
| 57 | ] |
||
| 58 | ), |
||
| 59 | |||
| 60 | 'created_at' => $this->getReadOnlyField( |
||
| 61 | __('created_at', 'Created'), |
||
| 62 | [ |
||
| 63 | 'display_in_list' => true |
||
| 64 | ] |
||
| 209 |