| Conditions | 4 |
| Paths | 4 |
| Total Lines | 74 |
| 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 |
||
| 97 | public function search($params) |
||
| 98 | { |
||
| 99 | $query = static::find(); |
||
| 100 | /* @var $query BaseUserQuery */ |
||
| 101 | $userClass = $this->userClass; |
||
| 102 | $query = $query->from("{$userClass::tableName()} {$this->userAlias}"); |
||
| 103 | $noInitUser = $userClass::buildNoInitModel(); |
||
| 104 | /* @var $noInitUser User */ |
||
| 105 | $profileClass = $noInitUser->profileClass; |
||
| 106 | if (!empty($profileClass)) { |
||
| 107 | $query = $query->joinWith(["profile {$this->profileAlias}"]); |
||
| 108 | } |
||
| 109 | $dataProvider = new ActiveDataProvider([ |
||
| 110 | 'query' => $query, |
||
| 111 | 'pagination' => [ |
||
| 112 | 'pageParam' => 'user-page', |
||
| 113 | 'defaultPageSize' => 20, |
||
| 114 | 'pageSizeParam' => 'user-per-page', |
||
| 115 | ], |
||
| 116 | 'sort' => [ |
||
| 117 | 'sortParam' => 'user-sort', |
||
| 118 | 'attributes' => [ |
||
| 119 | 'id', |
||
| 120 | 'nickname', |
||
| 121 | 'name' => [ |
||
| 122 | 'asc' => [$this->profileAlias . '.first_name' => SORT_ASC, $this->profileAlias . '.last_name' => SORT_ASC], |
||
| 123 | 'desc' => [$this->profileAlias . '.first_name' => SORT_DESC, $this->profileAlias . '.last_name' => SORT_DESC], |
||
| 124 | 'default' => SORT_DESC, |
||
| 125 | 'label' => Yii::t('user', 'Name'), |
||
| 126 | ], |
||
| 127 | 'gender' => [ |
||
| 128 | 'asc' => [$this->profileAlias . '.gender' => SORT_ASC], |
||
| 129 | 'desc' => [$this->profileAlias . '.gender' => SORT_DESC], |
||
| 130 | 'default' => SORT_ASC, |
||
| 131 | 'label' => Yii::t('user', 'Gender'), |
||
| 132 | ], |
||
| 133 | 'createdAt' => [ |
||
| 134 | 'asc' => [$this->userAlias . '.created_at' => SORT_ASC], |
||
| 135 | 'desc' => [$this->userAlias . '.created_at' => SORT_DESC], |
||
| 136 | 'default' => SORT_ASC, |
||
| 137 | 'label' => Yii::t('user', 'Creation Time'), |
||
| 138 | ], |
||
| 139 | 'updatedAt' => [ |
||
| 140 | 'asc' => [$this->userAlias . '.updated_at' => SORT_ASC], |
||
| 141 | 'desc' => [$this->userAlias . '.updated_at' => SORT_DESC], |
||
| 142 | 'default' => SORT_ASC, |
||
| 143 | 'label' => Yii::t('user', 'Last Updated Time'), |
||
| 144 | ], |
||
| 145 | ], |
||
| 146 | ], |
||
| 147 | ]); |
||
| 148 | |||
| 149 | if (!($this->load($params) && $this->validate())) { |
||
| 150 | return $dataProvider; |
||
| 151 | } |
||
| 152 | |||
| 153 | $query = $query->andFilterWhere([ |
||
| 154 | 'LIKE', $this->userAlias . '.id', $this->id, |
||
| 155 | ])->andFilterWhere([ |
||
| 156 | 'LIKE', $this->profileAlias . '.nickname', $this->nickname, |
||
| 157 | ])->andFilterWhere([ |
||
| 158 | '>=', $this->userAlias . '.created_at', $this->createdFromInUtc, |
||
| 159 | ])->andFilterWhere([ |
||
| 160 | '<=', $this->userAlias . '.created_at', $this->createdToInUtc, |
||
| 161 | ])->andFilterWhere([ |
||
| 162 | 'LIKE', $this->profileAlias . '.first_name', $this->first_name, |
||
| 163 | ])->andFilterWhere([ |
||
| 164 | 'LIKE', $this->profileAlias . '.last_name', $this->last_name, |
||
| 165 | ])->andFilterWhere([ |
||
| 166 | $this->profileAlias . '.gender' => $this->gf, |
||
| 167 | ]); |
||
| 168 | $dataProvider->query = $query; |
||
| 169 | return $dataProvider; |
||
| 170 | } |
||
| 171 | |||
| 189 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.