| Conditions | 4 |
| Paths | 8 |
| Total Lines | 58 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 37 | public function rules() |
||
| 38 | { |
||
| 39 | return [ |
||
| 40 | [ |
||
| 41 | ['default'], |
||
| 42 | 'integer', |
||
| 43 | ], |
||
| 44 | [ |
||
| 45 | [ |
||
| 46 | 'created_at', |
||
| 47 | 'updated_at', |
||
| 48 | ], |
||
| 49 | 'safe', |
||
| 50 | ], |
||
| 51 | [ |
||
| 52 | [ |
||
| 53 | 'locale', |
||
| 54 | 'shortName', |
||
| 55 | 'name', |
||
| 56 | ], |
||
| 57 | |||
| 58 | 'required', |
||
| 59 | ], |
||
| 60 | [ |
||
| 61 | 'locale', |
||
| 62 | 'string', |
||
| 63 | 'max' => 8, |
||
| 64 | ], |
||
| 65 | [ |
||
| 66 | 'shortName', |
||
| 67 | 'string', |
||
| 68 | 'max' => 3, |
||
| 69 | ], |
||
| 70 | [ |
||
| 71 | 'name', |
||
| 72 | 'string', |
||
| 73 | 'max' => 64, |
||
| 74 | ], |
||
| 75 | [ |
||
| 76 | 'locale', |
||
| 77 | 'unique', |
||
| 78 | 'skipOnError' => true, |
||
| 79 | 'targetClass' => static::class, |
||
| 80 | 'filter' => $this->getScenario() == self::SCENARIO_UPDATE ? 'id != '.$this->id : '' |
||
| 81 | ], |
||
| 82 | [ |
||
| 83 | 'shortName', |
||
| 84 | 'unique', |
||
| 85 | 'skipOnError' => true, |
||
| 86 | 'targetClass' => static::class, |
||
| 87 | 'filter' => $this->getScenario() == self::SCENARIO_UPDATE ? 'id != '.$this->id : '' |
||
| 88 | ], |
||
| 89 | [ |
||
| 90 | 'name', |
||
| 91 | 'unique', |
||
| 92 | 'skipOnError' => true, |
||
| 93 | 'targetClass' => static::class, |
||
| 94 | 'filter' => $this->getScenario() == self::SCENARIO_UPDATE ? 'id != '.$this->id : '' |
||
| 95 | ], |
||
| 216 |