| Conditions | 4 |
| Paths | 2 |
| Total Lines | 55 |
| Code Lines | 29 |
| 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 |
||
| 41 | public function rules() |
||
| 42 | { |
||
| 43 | return [ |
||
| 44 | [ |
||
| 45 | [ |
||
| 46 | 'created_at', |
||
| 47 | 'updated_at', |
||
| 48 | ], |
||
| 49 | 'safe', |
||
| 50 | ], |
||
| 51 | [ |
||
| 52 | [ |
||
| 53 | 'active', |
||
| 54 | ], |
||
| 55 | 'required', |
||
| 56 | ], |
||
| 57 | [ |
||
| 58 | [ |
||
| 59 | 'parentId', |
||
| 60 | 'active' |
||
| 61 | ], |
||
| 62 | 'integer', |
||
| 63 | ], |
||
| 64 | [ |
||
| 65 | [ |
||
| 66 | 'icon', |
||
| 67 | 'alias', |
||
| 68 | ], |
||
| 69 | 'string', |
||
| 70 | 'max' => 128, |
||
| 71 | ], |
||
| 72 | [ |
||
| 73 | 'parentId', |
||
| 74 | 'filter', |
||
| 75 | 'filter' => function ($value) { |
||
| 76 | if (empty($value)) { |
||
| 77 | return null; |
||
| 78 | } else { |
||
| 79 | return MenuWidget::checkNewParentId($this, $value) ? $value : $this->getOldAttribute('parentId'); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | ], |
||
| 83 | [ |
||
| 84 | 'alias', |
||
| 85 | 'filter', |
||
| 86 | 'filter' => function ($value) { |
||
| 87 | return preg_replace( '/[^a-z0-9_]+/', '-', strtolower(trim($value))); |
||
| 88 | } |
||
| 89 | ], |
||
| 90 | [ |
||
| 91 | 'alias', |
||
| 92 | 'unique', |
||
| 93 | 'skipOnError' => true, |
||
| 94 | 'targetClass' => static::class, |
||
| 95 | 'filter' => $this->getScenario() == ModelInterface::SCENARIO_UPDATE ? 'id != '.$this->id : '' |
||
| 96 | ], |
||
| 186 |