Conditions | 23 |
Paths | 32 |
Total Lines | 111 |
Code Lines | 69 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 0 | Features | 1 |
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 |
||
173 | public function addWhereCondition($model, array $filters, $type = 'and', $index = 0) |
||
174 | { |
||
175 | // Get key and value |
||
176 | $firstFilterKey = array_key_first($filters); |
||
177 | if ($firstFilterKey === null) { |
||
178 | return $model; |
||
179 | } |
||
180 | $firstFilterValue = $filters[$firstFilterKey]; |
||
181 | |||
182 | switch ($firstFilterKey) { |
||
183 | // if final query |
||
184 | case $this->queryFilterTitle: |
||
185 | |||
186 | $firstFilterInnerKey = array_key_first($filters[$firstFilterKey]); |
||
187 | if ($firstFilterInnerKey === null) { |
||
188 | return $model; |
||
189 | } |
||
190 | |||
191 | // if not first record and type is or |
||
192 | if ($type == "or" && $index > 0) { |
||
193 | $model = $model->orWhere([$firstFilterValue[$firstFilterInnerKey]]); |
||
194 | } else { |
||
195 | $whereCondition = $firstFilterValue[$firstFilterInnerKey]; |
||
196 | if (strtolower($whereCondition[2]) == "null") { |
||
197 | if ( |
||
198 | strtolower($whereCondition[1]) == "is" || |
||
199 | $whereCondition[1] == "=" |
||
200 | ) { |
||
201 | $model = $model->whereNull($whereCondition[0]); |
||
202 | } elseif ( |
||
203 | strtolower($whereCondition[1]) == "not" || |
||
204 | $whereCondition[1] == "<>" || |
||
205 | $whereCondition[1] == "!=" |
||
206 | ) { |
||
207 | $model = $model->whereNotNull($whereCondition[0]); |
||
208 | } |
||
209 | } else { |
||
210 | if ( |
||
211 | strtolower($whereCondition[1]) == "in" |
||
212 | ) { |
||
213 | $model = $model->whereIn( |
||
214 | $whereCondition[0], |
||
215 | json_decode($whereCondition[2], true) |
||
216 | ); |
||
217 | } else { |
||
218 | $model = $model->where([$whereCondition]); |
||
219 | } |
||
220 | } |
||
221 | } |
||
222 | |||
223 | // Get Inner key and value |
||
224 | if (count($filters[$firstFilterKey]) === 1) { |
||
225 | break; |
||
226 | } |
||
227 | unset($filters[$firstFilterKey][$firstFilterInnerKey]); |
||
228 | return $this->addWhereCondition($model, $filters, $type, ++$index); |
||
229 | |||
230 | // if and |
||
231 | case 'and_' . $this->queryFilterTitle: |
||
232 | // if not first record and type is or |
||
233 | if ($type == "or" && $index > 0) { |
||
234 | $model = $model->orWhere(function (Builder $builder) use ($firstFilterValue) { |
||
235 | $builder = $this->addWhereCondition($builder, $firstFilterValue, 'and', 0); |
||
236 | return $builder; |
||
237 | }); |
||
238 | } else { |
||
239 | $model = $model->where(function (Builder $builder) use ($firstFilterValue) { |
||
240 | $builder = $this->addWhereCondition($builder, $firstFilterValue, 'and', 0); |
||
241 | return $builder; |
||
242 | }); |
||
243 | } |
||
244 | break; |
||
245 | |||
246 | // if or |
||
247 | case 'or_' . $this->queryFilterTitle: |
||
248 | // if not first record and type is or |
||
249 | if ($type == "or" && $index > 0) { |
||
250 | $model = $model->orWhere(function (Builder $builder) use ($firstFilterValue) { |
||
251 | $builder = $this->addWhereCondition($builder, $firstFilterValue, 'or', 0); |
||
252 | return $builder; |
||
253 | }); |
||
254 | } else { |
||
255 | $model = $model->where(function (Builder $builder) use ($firstFilterValue) { |
||
256 | $builder = $this->addWhereCondition($builder, $firstFilterValue, 'or', 0); |
||
257 | return $builder; |
||
258 | }); |
||
259 | } |
||
260 | break; |
||
261 | |||
262 | // if relational |
||
263 | default: |
||
264 | // if not first record and type is or |
||
265 | if ($type == "or" && $index > 0) { |
||
266 | $model = $model->orWhereHas($firstFilterKey, function (Builder $builder) use ($firstFilterValue) { |
||
267 | $builder = $this->addWhereCondition($builder, $firstFilterValue, 'or', 0); |
||
268 | return $builder; |
||
269 | }); |
||
270 | } else { |
||
271 | $model = $model->whereHas($firstFilterKey, function (Builder $builder) use ($firstFilterValue) { |
||
272 | $builder = $this->addWhereCondition($builder, $firstFilterValue, 'and', 0); |
||
273 | return $builder; |
||
274 | }); |
||
275 | } |
||
276 | break; |
||
277 | } |
||
278 | |||
279 | unset($filters[$firstFilterKey]); |
||
280 | if (count($filters)) { |
||
281 | return $this->addWhereCondition($model, $filters, $type, ++$index); |
||
282 | } |
||
283 | return $model; |
||
284 | } |
||
337 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths