Conditions | 11 |
Paths | 768 |
Total Lines | 60 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
30 | public function getCustomFilters(array $filters): LengthAwarePaginator |
||
31 | { |
||
32 | $data = Post::query(); |
||
33 | |||
34 | if ($filters['tags'] !== null) { |
||
35 | $tags = array_filter((array) $filters['tags']); |
||
36 | |||
37 | $data = $data->whereHas('tags', function (Builder $query) use ($tags): void { |
||
38 | $query->whereIn('tags.id', $tags); |
||
39 | }); |
||
40 | } |
||
41 | |||
42 | if ($filters['categories'] !== null) { |
||
43 | $categories = array_filter((array) $filters['categories']); |
||
44 | |||
45 | $data = $data->whereHas('categories', function (Builder $query) use ($categories): void { |
||
46 | $query->whereIn('categories.id', $categories); |
||
47 | }); |
||
48 | } |
||
49 | |||
50 | if ($filters['categories_exclude'] !== null) { |
||
51 | $data = $data |
||
52 | ->whereHas('categories', function (Builder $query) use ($filters): void { |
||
53 | $query->whereNotIn('categories.id', array_filter((array) $filters['categories_exclude'])); |
||
54 | }); |
||
55 | } |
||
56 | |||
57 | if ($filters['exclude'] !== null) { |
||
58 | $data = $data->whereNotIn('id', array_filter((array) $filters['exclude'])); |
||
59 | } |
||
60 | |||
61 | if ($filters['include'] !== null) { |
||
62 | $data = $data->whereNotIn('id', array_filter((array) $filters['include'])); |
||
63 | } |
||
64 | |||
65 | if ($filters['author'] !== null) { |
||
66 | $data = $data->whereIn('author_id', array_filter((array) $filters['author'])); |
||
67 | } |
||
68 | |||
69 | if ($filters['author_exclude'] !== null) { |
||
70 | $data = $data->whereNotIn('author_id', array_filter((array) $filters['author_exclude'])); |
||
71 | } |
||
72 | |||
73 | if ($filters['featured'] !== null) { |
||
74 | $data = $data->where('is_featured', $filters['featured']); |
||
75 | } |
||
76 | |||
77 | if ($filters['search'] !== null) { |
||
78 | $keyword = isset($filters['search']) ? (string) $filters['search'] : null; |
||
79 | $data = $this->search($data, $keyword); |
||
80 | } |
||
81 | |||
82 | $orderBy = Arr::get($filters, 'order_by', 'updated_at'); |
||
83 | $order = Arr::get($filters, 'order', 'desc'); |
||
84 | |||
85 | $data = $data |
||
86 | ->wherePublished() |
||
87 | ->orderBy($orderBy, $order); |
||
88 | |||
89 | return $data->paginate((int) $filters['per_page']); |
||
90 | } |
||
125 |
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