| Conditions | 3 |
| Paths | 2 |
| Total Lines | 65 |
| Code Lines | 51 |
| 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 |
||
| 87 | public function search($params) |
||
| 88 | { |
||
| 89 | $query = static::find(); |
||
| 90 | $dataProvider = new ActiveDataProvider([ |
||
| 91 | 'query' => $query, |
||
| 92 | 'pagination' => [ |
||
| 93 | 'pageParam' => 'user-page', |
||
| 94 | 'defaultPageSize' => 20, |
||
| 95 | 'pageSizeParam' => 'user-per-page', |
||
| 96 | ], |
||
| 97 | 'sort' => [ |
||
| 98 | 'sortParam' => 'user-sort', |
||
| 99 | 'attributes' => [ |
||
| 100 | 'id', |
||
| 101 | 'nickname', |
||
| 102 | 'name' => [ |
||
| 103 | 'asc' => ['first_name' => SORT_ASC, 'last_name' => SORT_ASC], |
||
| 104 | 'desc' => ['first_name' => SORT_DESC, 'last_name' => SORT_DESC], |
||
| 105 | 'default' => SORT_DESC, |
||
| 106 | 'label' => Yii::t('user', 'Name'), |
||
| 107 | ], |
||
| 108 | 'gender' => [ |
||
| 109 | 'asc' => ['gender' => SORT_ASC], |
||
| 110 | 'desc' => ['gender' => SORT_DESC], |
||
| 111 | 'default' => SORT_ASC, |
||
| 112 | 'label' => Yii::t('user', 'Gender'), |
||
| 113 | ], |
||
| 114 | 'createdAt' => [ |
||
| 115 | 'asc' => ['created_at' => SORT_ASC], |
||
| 116 | 'desc' => ['created_at' => SORT_DESC], |
||
| 117 | 'default' => SORT_ASC, |
||
| 118 | 'label' => Yii::t('user', 'Creation Time'), |
||
| 119 | ], |
||
| 120 | 'updatedAt' => [ |
||
| 121 | 'asc' => ['updated_at' => SORT_ASC], |
||
| 122 | 'desc' => ['updated_at' => SORT_DESC], |
||
| 123 | 'default' => SORT_ASC, |
||
| 124 | 'label' => Yii::t('user', 'Last Updated Time'), |
||
| 125 | ], |
||
| 126 | ], |
||
| 127 | ], |
||
| 128 | ]); |
||
| 129 | |||
| 130 | if (!($this->load($params) && $this->validate())) { |
||
| 131 | return $dataProvider; |
||
| 132 | } |
||
| 133 | |||
| 134 | $query = $query->andFilterWhere([ |
||
| 135 | 'LIKE', 'id', $this->id, |
||
| 136 | ])->andFilterWhere([ |
||
| 137 | 'LIKE', 'nickname', $this->nickname, |
||
| 138 | ])->andFilterWhere([ |
||
| 139 | '>=', 'created_at', $this->createdFromInUtc, |
||
| 140 | ])->andFilterWhere([ |
||
| 141 | '<=', 'created_at', $this->createdToInUtc, |
||
| 142 | ])->andFilterWhere([ |
||
| 143 | 'LIKE', 'first_name', $this->first_name, |
||
| 144 | ])->andFilterWhere([ |
||
| 145 | 'LIKE', 'last_name', $this->last_name, |
||
| 146 | ])->andFilterWhere([ |
||
| 147 | 'gender' => $this->gf, |
||
| 148 | ]); |
||
| 149 | $dataProvider->query = $query; |
||
| 150 | return $dataProvider; |
||
| 151 | } |
||
| 152 | |||
| 165 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.