| Conditions | 3 |
| Paths | 2 |
| Total Lines | 71 |
| Code Lines | 57 |
| 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 |
||
| 163 | public function search($params) |
||
| 164 | { |
||
| 165 | $query = $this->query; |
||
| 166 | $dataProvider = new ActiveDataProvider([ |
||
| 167 | 'query' => $query, |
||
| 168 | 'pagination' => [ |
||
| 169 | 'pageParam' => 'member-page', |
||
| 170 | 'defaultPageSize' => 20, |
||
| 171 | 'pageSizeParam' => 'member-per-page', |
||
| 172 | ], |
||
| 173 | 'sort' => [ |
||
| 174 | 'sortParam' => 'member-sort', |
||
| 175 | 'attributes' => [ |
||
| 176 | 'id' => [ |
||
| 177 | 'asc' => [$this->memberUserAlias . '.id' => SORT_ASC], |
||
| 178 | 'desc' => [$this->memberUserAlias . '.id' => SORT_DESC], |
||
| 179 | 'default' => SORT_ASC, |
||
| 180 | 'label' => Yii::t('user', 'User ID'), |
||
| 181 | ], |
||
| 182 | 'name' => [ |
||
| 183 | 'asc' => [$this->profileAlias . '.first_name' => SORT_ASC, $this->profileAlias . '.last_name' => SORT_ASC], |
||
| 184 | 'desc' => [$this->profileAlias . '.first_name' => SORT_DESC, $this->profileAlias . '.last_name' => SORT_DESC], |
||
| 185 | 'default' => SORT_DESC, |
||
| 186 | 'label' => Yii::t('user', 'Name'), |
||
| 187 | ], |
||
| 188 | 'position', |
||
| 189 | 'role', |
||
| 190 | 'created_at' => [ |
||
| 191 | 'asc' => [$this->memberAlias . '.created_at' => SORT_ASC], |
||
| 192 | 'desc' => [$this->memberAlias . '.created_at' => SORT_DESC], |
||
| 193 | 'default' => SORT_ASC, |
||
| 194 | 'label' => Yii::t('user', 'Creation Time'), |
||
| 195 | ], |
||
| 196 | 'updated_at' => [ |
||
| 197 | 'asc' => [$this->memberAlias . '.updated_at' => SORT_ASC], |
||
| 198 | 'desc' => [$this->memberAlias . '.updated_at' => SORT_DESC], |
||
| 199 | 'default' => SORT_ASC, |
||
| 200 | 'label' => Yii::t('user', 'Last Updated Time'), |
||
| 201 | ], |
||
| 202 | ], |
||
| 203 | ], |
||
| 204 | ]); |
||
| 205 | |||
| 206 | if (!($this->load($params) && $this->validate())) { |
||
| 207 | return $dataProvider; |
||
| 208 | } |
||
| 209 | |||
| 210 | $query = $query->andFilterWhere([ |
||
| 211 | 'LIKE', $this->memberUserAlias . '.id', $this->id, |
||
| 212 | ])->andFilterWhere([ |
||
| 213 | 'LIKE', $this->profileAlias . '.nickname', $this->nickname, |
||
| 214 | ])->andFilterWhere([ |
||
| 215 | 'LIKE', $this->profileAlias . '.first_name', $this->first_name, |
||
| 216 | ])->andFilterWhere([ |
||
| 217 | 'LIKE', $this->profileAlias . '.last_name', $this->last_name, |
||
| 218 | ])->andFilterWhere([ |
||
| 219 | $this->profileAlias . '.gender' => $this->gender, |
||
| 220 | ])->andFilterWhere([ |
||
| 221 | 'LIKE', $this->memberAlias . '.position', $this->position, |
||
| 222 | ])->andFilterWhere([ |
||
| 223 | 'LIKE', $this->memberAlias . '.description', $this->description, |
||
| 224 | ])->andFilterWhere([ |
||
| 225 | $this->memberAlias . '.role' => $this->roleInDb, |
||
| 226 | ])->andFilterWhere([ |
||
| 227 | '>=', $this->memberAlias . '.created_at', $this->createdFromInUtc, |
||
| 228 | ])->andFilterWhere([ |
||
| 229 | '<=', $this->memberAlias . '.created_at', $this->createdToInUtc, |
||
| 230 | ]); |
||
| 231 | $dataProvider->query = $query; |
||
| 232 | return $dataProvider; |
||
| 233 | } |
||
| 234 | |||
| 254 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.