Conditions | 3 |
Paths | 2 |
Total Lines | 63 |
Code Lines | 49 |
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 |
||
158 | public function search($params) |
||
159 | { |
||
160 | $query = $this->query; |
||
161 | $dataProvider = new ActiveDataProvider([ |
||
162 | 'query' => $query, |
||
163 | 'pagination' => [ |
||
164 | 'pageParam' => 'organization-page', |
||
165 | 'defaultPageSize' => 20, |
||
166 | 'pageSizeParam' => 'organization-per-page', |
||
167 | ], |
||
168 | 'sort' => [ |
||
169 | 'sortParam' => 'organization-sort', |
||
170 | 'attributes' => [ |
||
171 | 'id', |
||
172 | 'nickname' => [ |
||
173 | 'asc' => [$this->profileAlias . '.nickname' => SORT_ASC], |
||
174 | 'desc' => [$this->profileAlias . '.nickname' => SORT_DESC], |
||
175 | 'default' => SORT_ASC, |
||
176 | 'label' => Yii::t('user', 'Nickname'), |
||
177 | ], |
||
178 | 'name', |
||
179 | 'type' => [ |
||
180 | 'asc' => [$this->organizationAlias . '.type' => SORT_ASC], |
||
181 | 'desc' => [$this->organizationAlias . '.type' => SORT_DESC], |
||
182 | 'default' => SORT_ASC, |
||
183 | 'label' => Yii::t('user', 'Type'), |
||
184 | ], |
||
185 | 'created_at' => [ |
||
186 | 'asc' => [$this->organizationAlias . '.created_at' => SORT_ASC], |
||
187 | 'desc' => [$this->organizationAlias . '.created_at' => SORT_DESC], |
||
188 | 'default' => SORT_ASC, |
||
189 | 'label' => Yii::t('user', 'Creation Time'), |
||
190 | ], |
||
191 | 'updated_at' => [ |
||
192 | 'asc' => [$this->organizationAlias . '.updated_at' => SORT_ASC], |
||
193 | 'desc' => [$this->organizationAlias . '.updated_at' => SORT_DESC], |
||
194 | 'default' => SORT_ASC, |
||
195 | 'label' => Yii::t('user', 'Last Updated Time'), |
||
196 | ], |
||
197 | ], |
||
198 | ], |
||
199 | ]); |
||
200 | |||
201 | if (!($this->load($params) && $this->validate())) { |
||
202 | return $dataProvider; |
||
203 | } |
||
204 | |||
205 | $query = $query->andFilterWhere([ |
||
206 | 'LIKE', $this->organizationAlias . '.id', $this->id, |
||
207 | ])->andFilterWhere([ |
||
208 | 'LIKE', $this->profileAlias . '.nickname', $this->nickname, |
||
209 | ])->andFilterWhere([ |
||
210 | '>=', $this->organizationAlias . '.created_at', $this->createdFromInUtc, |
||
211 | ])->andFilterWhere([ |
||
212 | '<=', $this->organizationAlias . '.created_at', $this->createdToInUtc, |
||
213 | ])->andFilterWhere([ |
||
214 | 'LIKE', $this->profileAlias . '.name', $this->name, |
||
215 | ])->andFilterWhere([ |
||
216 | $this->organizationAlias . '.type' => $this->type, |
||
217 | ]); |
||
218 | $dataProvider->query = $query; |
||
219 | return $dataProvider; |
||
220 | } |
||
221 | |||
238 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.