Conditions | 33 |
Paths | 2 |
Total Lines | 77 |
Code Lines | 59 |
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 |
||
20 | public function scopeFilterable($query, array $filterAttributes = null) |
||
21 | { |
||
22 | $filterable = $this->getFilterable(); |
||
23 | $attributes = $this->getFilterAttributes($filterAttributes); |
||
24 | |||
25 | if (! empty($attributes)) { |
||
26 | $query->where(function ($q) use ($attributes, $filterable) { |
||
27 | foreach ($filterable as $key => $filterType) { |
||
28 | switch ($filterType) { |
||
29 | case 'equal': |
||
30 | if (array_key_exists($key, $attributes) && $attributes[$key] !== null) { |
||
31 | $this->fWhereEqual($q, $key, $attributes); |
||
32 | } |
||
33 | break; |
||
34 | case 'like': |
||
35 | if (array_key_exists($key, $attributes) && $attributes[$key] !== null) { |
||
36 | $q->where($key, 'LIKE', '%' . $attributes[$key] . '%'); |
||
37 | } |
||
38 | break; |
||
39 | case 'in': |
||
40 | if (array_key_exists($key, $attributes) && $attributes[$key] !== null) { |
||
41 | $this->fWhereIn($q, $key, $attributes); |
||
42 | } |
||
43 | break; |
||
44 | case 'between': |
||
45 | $fromVal = $attributes[$key . '_from'] ?? null; |
||
46 | $toVal = $attributes[$key . '_to'] ?? null; |
||
47 | if ($fromVal != null && $toVal != null) { |
||
48 | $q->whereBetween($key, [$fromVal, $toVal]); |
||
49 | } elseif ($fromVal != null && $toVal == null) { |
||
50 | $q->where($key, '>=', $fromVal); |
||
51 | } elseif ($fromVal == null && $toVal != null) { |
||
52 | $q->where($key, '<=', $toVal); |
||
53 | } |
||
54 | break; |
||
55 | case 'equal_date': |
||
56 | if (array_key_exists($key, $attributes)) { |
||
57 | try { |
||
58 | $date = Carbon::parse($attributes[$key])->toDateString(); |
||
59 | $q->whereDate($key, $date); |
||
60 | } catch (\Exception $exception) { |
||
61 | \Log::error(__METHOD__ . $exception->getMessage()); |
||
62 | } |
||
63 | } |
||
64 | break; |
||
65 | case 'between_date': |
||
66 | $fromVal = $attributes[$key . '_from'] ?? null; |
||
67 | $toVal = $attributes[$key . '_to'] ?? null; |
||
68 | |||
69 | try { |
||
70 | if ($fromVal != null && $toVal != null) { |
||
71 | $dateFrom = Carbon::parse($fromVal); |
||
72 | $dateTo = Carbon::parse($toVal)->addDay()->addSecond(-1); |
||
73 | $q->whereBetween($key, [$dateFrom, $dateTo]); |
||
74 | } elseif ($fromVal != null && $toVal == null) { |
||
75 | $dateFrom = Carbon::parse($fromVal); |
||
76 | $q->where($key, '>=', $dateFrom); |
||
77 | } elseif ($fromVal == null && $toVal != null) { |
||
78 | $dateTo = Carbon::parse($toVal)->addDay()->addSecond(-1); |
||
79 | $q->where($key, '<=', $dateTo); |
||
80 | } |
||
81 | } catch (\Exception $exception) { |
||
82 | \Log::error(__METHOD__ . $exception->getMessage()); |
||
83 | } |
||
84 | break; |
||
85 | case 'custom': |
||
86 | $method = 'scopeCustomFilterable'; |
||
87 | if (array_key_exists($key, $attributes) && method_exists(self::class, $method)) { |
||
88 | $this->{$method}($q, $key, $attributes[$key]); |
||
89 | } |
||
90 | break; |
||
91 | } |
||
92 | } |
||
93 | }); |
||
94 | } |
||
95 | |||
96 | return $query; |
||
97 | } |
||
251 | } |
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