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 |
||
144 | public function search($params) |
||
145 | { |
||
146 | $query = $this->query; |
||
147 | $dataProvider = new ActiveDataProvider([ |
||
148 | 'query' => $query, |
||
149 | 'pagination' => [ |
||
150 | 'pageParam' => 'organization-page', |
||
151 | 'defaultPageSize' => 20, |
||
152 | 'pageSizeParam' => 'organization-per-page', |
||
153 | ], |
||
154 | 'sort' => [ |
||
155 | 'sortParam' => 'organization-sort', |
||
156 | 'attributes' => [ |
||
157 | 'id', |
||
158 | 'nickname' => [ |
||
159 | 'asc' => [$this->profileAlias . '.nickname' => SORT_ASC], |
||
160 | 'desc' => [$this->profileAlias . '.nickname' => SORT_DESC], |
||
161 | 'default' => SORT_ASC, |
||
162 | 'label' => Yii::t('user', 'Nickname'), |
||
163 | ], |
||
164 | 'name', |
||
165 | 'type' => [ |
||
166 | 'asc' => [$this->organizationAlias . '.type' => SORT_ASC], |
||
167 | 'desc' => [$this->organizationAlias . '.type' => SORT_DESC], |
||
168 | 'default' => SORT_ASC, |
||
169 | 'label' => Yii::t('user', 'Type'), |
||
170 | ], |
||
171 | 'created_at' => [ |
||
172 | 'asc' => [$this->organizationAlias . '.created_at' => SORT_ASC], |
||
173 | 'desc' => [$this->organizationAlias . '.created_at' => SORT_DESC], |
||
174 | 'default' => SORT_ASC, |
||
175 | 'label' => Yii::t('user', 'Creation Time'), |
||
176 | ], |
||
177 | 'updated_at' => [ |
||
178 | 'asc' => [$this->organizationAlias . '.updated_at' => SORT_ASC], |
||
179 | 'desc' => [$this->organizationAlias . '.updated_at' => SORT_DESC], |
||
180 | 'default' => SORT_ASC, |
||
181 | 'label' => Yii::t('user', 'Last Updated Time'), |
||
182 | ], |
||
183 | ], |
||
184 | ], |
||
185 | ]); |
||
186 | |||
187 | if (!($this->load($params) && $this->validate())) { |
||
188 | return $dataProvider; |
||
189 | } |
||
190 | |||
191 | $query = $query->andFilterWhere([ |
||
192 | 'LIKE', $this->organizationAlias . '.id', $this->id, |
||
193 | ])->andFilterWhere([ |
||
194 | 'LIKE', $this->profileAlias . '.nickname', $this->nickname, |
||
195 | ])->andFilterWhere([ |
||
196 | '>=', $this->organizationAlias . '.created_at', $this->createdFromInUtc, |
||
197 | ])->andFilterWhere([ |
||
198 | '<=', $this->organizationAlias . '.created_at', $this->createdToInUtc, |
||
199 | ])->andFilterWhere([ |
||
200 | 'LIKE', $this->profileAlias . '.name', $this->name, |
||
201 | ])->andFilterWhere([ |
||
202 | $this->organizationAlias . '.type' => $this->type, |
||
203 | ]); |
||
204 | $dataProvider->query = $query; |
||
205 | return $dataProvider; |
||
206 | } |
||
207 | |||
224 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.