Conditions | 2 |
Paths | 1 |
Total Lines | 56 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
74 | public function rules() |
||
75 | { |
||
76 | return [ |
||
77 | [['name', 'frequency', 'transaction_id'], 'required'], |
||
78 | [['user_id', 'interval', 'transaction_id'], 'integer'], |
||
79 | ['frequency', 'in', 'range' => RecurrenceFrequency::names()], |
||
80 | ['status', 'in', 'range' => RecurrenceStatus::names()], |
||
81 | [['started_at', 'execution_date'], 'datetime', 'format' => 'php:Y-m-d'], |
||
82 | [['name'], 'string', 'max' => 255], |
||
83 | [ |
||
84 | 'transaction_id', |
||
85 | function ($attribute, $params, $validator) { |
||
86 | try { |
||
87 | TransactionService::findCurrentOne($this->$attribute); |
||
88 | } catch (\Exception $e) { |
||
89 | $this->addError( |
||
90 | $attribute, |
||
91 | Yii::t('app', 'The {attribute} not found.', ['attribute' => $attribute]) |
||
92 | ); |
||
93 | return null; |
||
94 | } |
||
95 | } |
||
96 | ], |
||
97 | [ |
||
98 | 'schedule', |
||
99 | 'required', |
||
100 | 'when' => function (self $model) { |
||
101 | return in_array( |
||
102 | RecurrenceFrequency::toEnumValue($model->frequency), |
||
103 | [RecurrenceFrequency::WEEK, RecurrenceFrequency::MONTH, RecurrenceFrequency::YEAR] |
||
104 | ); |
||
105 | } |
||
106 | ], |
||
107 | [ |
||
108 | 'schedule', |
||
109 | 'integer', |
||
110 | 'min' => 1, |
||
111 | 'max' => 7, |
||
112 | 'when' => function (self $model) { |
||
113 | return RecurrenceFrequency::toEnumValue($model->frequency) === RecurrenceFrequency::WEEK; |
||
114 | } |
||
115 | ], |
||
116 | [ |
||
117 | 'schedule', |
||
118 | 'datetime', |
||
119 | 'format' => 'd', |
||
120 | 'when' => function (self $model) { |
||
121 | return RecurrenceFrequency::toEnumValue($model->frequency) === RecurrenceFrequency::MONTH; |
||
122 | } |
||
123 | ], |
||
124 | [ |
||
125 | 'schedule', |
||
126 | 'datetime', |
||
127 | 'format' => 'M-d', |
||
128 | 'when' => function (self $model) { |
||
129 | return RecurrenceFrequency::toEnumValue($model->frequency) === RecurrenceFrequency::YEAR; |
||
130 | } |
||
223 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.