| Conditions | 4 |
| Paths | 4 |
| Total Lines | 61 |
| Code Lines | 46 |
| 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 |
||
| 93 | public function search($params) |
||
| 94 | { |
||
| 95 | $query = static::find(); |
||
| 96 | /* @var $query OrganizationQuery */ |
||
| 97 | $class = $this->organizationClass; |
||
| 98 | $query = $query->from("{$class::tableName()} {$this->organizationAlias}"); |
||
| 99 | $noInitOrg = new $class; |
||
| 100 | /* @var $noInitOrg Organization */ |
||
| 101 | $profileClass = $noInitOrg->profileClass; |
||
| 102 | if (!empty($profileClass)) { |
||
| 103 | $query = $query->joinWith(["profile {$this->profileAlias}"]); |
||
| 104 | } |
||
| 105 | $dataProvider = new ActiveDataProvider([ |
||
| 106 | 'query' => $query, |
||
| 107 | 'pagination' => [ |
||
| 108 | 'pageParam' => 'organization-page', |
||
| 109 | 'defaultPageSize' => 20, |
||
| 110 | 'pageSizeParam' => 'organization-per-page', |
||
| 111 | ], |
||
| 112 | 'sort' => [ |
||
| 113 | 'sortParam' => 'organization-sort', |
||
| 114 | 'attributes' => [ |
||
| 115 | 'id', |
||
| 116 | 'nickname', |
||
| 117 | 'name', |
||
| 118 | 'createdAt' => [ |
||
| 119 | 'asc' => [$this->organizationAlias . '.created_at' => SORT_ASC], |
||
| 120 | 'desc' => [$this->organizationAlias . '.created_at' => SORT_DESC], |
||
| 121 | 'default' => SORT_ASC, |
||
| 122 | 'label' => Yii::t('user', 'Creation Time'), |
||
| 123 | ], |
||
| 124 | 'updatedAt' => [ |
||
| 125 | 'asc' => [$this->organizationAlias . '.updated_at' => SORT_ASC], |
||
| 126 | 'desc' => [$this->organizationAlias . '.updated_at' => SORT_DESC], |
||
| 127 | 'default' => SORT_ASC, |
||
| 128 | 'label' => Yii::t('user', 'Last Updated Time'), |
||
| 129 | ], |
||
| 130 | ], |
||
| 131 | ], |
||
| 132 | ]); |
||
| 133 | |||
| 134 | if (!($this->load($params) && $this->validate())) { |
||
| 135 | return $dataProvider; |
||
| 136 | } |
||
| 137 | |||
| 138 | $query = $query->andFilterWhere([ |
||
| 139 | 'LIKE', $this->organizationAlias . '.id', $this->id, |
||
| 140 | ])->andFilterWhere([ |
||
| 141 | 'LIKE', $this->profileAlias . '.nickname', $this->nickname, |
||
| 142 | ])->andFilterWhere([ |
||
| 143 | '>=', $this->organizationAlias . '.created_at', $this->createdFromInUtc, |
||
| 144 | ])->andFilterWhere([ |
||
| 145 | '<=', $this->organizationAlias . '.created_at', $this->createdToInUtc, |
||
| 146 | ])->andFilterWhere([ |
||
| 147 | 'LIKE', $this->profileAlias . '.name', $this->name, |
||
| 148 | ])->andFilterWhere([ |
||
| 149 | 'type' => $this->type, |
||
| 150 | ]); |
||
| 151 | $dataProvider->query = $query; |
||
| 152 | return $dataProvider; |
||
| 153 | } |
||
| 154 | |||
| 171 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.