Conditions | 13 |
Paths | 37 |
Total Lines | 57 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
129 | public function apply(ColumnInterface $column, Builder $query, $queryString, $queryParams) |
||
130 | { |
||
131 | $queryString = $this->parseValue($queryString); |
||
132 | |||
133 | if (($metaInstance = $column->getMetaData()) instanceof ColumnMetaInterface) { |
||
|
|||
134 | if (method_exists($metaInstance, 'onFilterSearch')) { |
||
135 | $metaInstance->onFilterSearch($column, $query, $queryString, $queryParams); |
||
136 | |||
137 | return; |
||
138 | } |
||
139 | } |
||
140 | |||
141 | if (is_callable($callback = $column->getFilterCallback())) { |
||
142 | $callback($column, $query, $queryString, $queryParams); |
||
143 | |||
144 | return; |
||
145 | } |
||
146 | |||
147 | if (is_callable($callback = $this->getCallback())) { |
||
148 | $callback($column, $query, $queryString, $queryParams); |
||
149 | |||
150 | return; |
||
151 | } |
||
152 | |||
153 | if (empty($queryString) && strlen($queryString) == 0) { |
||
154 | return; |
||
155 | } |
||
156 | |||
157 | if (is_null($name = $this->getColumnRawName())) { |
||
158 | if (is_null($name = $this->getColumnName())) { |
||
159 | $name = $column->getName(); |
||
160 | } |
||
161 | } |
||
162 | |||
163 | if (strpos($name, '.') !== false && is_null($this->getColumnRawName())) { |
||
164 | $parts = explode('.', $name); |
||
165 | $fieldName = array_pop($parts); |
||
166 | $relationName = implode('.', $parts); |
||
167 | try { |
||
168 | $relation = $query->getModel()->{$relationName}(); |
||
169 | $isMorphTo = $relation instanceof \Illuminate\Database\Eloquent\Relations\MorphTo; |
||
170 | } catch (\Exception $e) { |
||
171 | $isMorphTo = false; |
||
172 | } |
||
173 | |||
174 | if ($isMorphTo) { |
||
175 | $query->whereHasMorph($relationName, '*', function ($q) use ($queryString, $fieldName) { |
||
176 | $this->buildQuery($q, $fieldName, $queryString); |
||
177 | }); |
||
178 | } else { |
||
179 | $query->whereHas($relationName, function ($q) use ($queryString, $fieldName) { |
||
180 | $this->buildQuery($q, $fieldName, $queryString); |
||
181 | }); |
||
182 | } |
||
183 | unset($relation); |
||
184 | } else { |
||
185 | $this->buildQuery($query, $name, $queryString); |
||
186 | } |
||
202 |