| 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 |
||
| 28 | public function getCustomFilters(array $filters): LengthAwarePaginator |
||
| 29 | { |
||
| 30 | $data = Post::query(); |
||
| 31 | |||
| 32 | if ($filters['tags'] !== null) { |
||
| 33 | $tags = array_filter((array) $filters['tags']); |
||
| 34 | |||
| 35 | $data = $data->whereHas('tags', function (Builder $query) use ($tags): void { |
||
| 36 | $query->whereIn('tags.id', $tags); |
||
| 37 | }); |
||
| 38 | } |
||
| 39 | |||
| 40 | if ($filters['categories'] !== null) { |
||
| 41 | $categories = array_filter((array) $filters['categories']); |
||
| 42 | |||
| 43 | $data = $data->whereHas('categories', function (Builder $query) use ($categories): void { |
||
| 44 | $query->whereIn('categories.id', $categories); |
||
| 45 | }); |
||
| 46 | } |
||
| 47 | |||
| 48 | if ($filters['categories_exclude'] !== null) { |
||
| 49 | $data = $data |
||
| 50 | ->whereHas('categories', function (Builder $query) use ($filters): void { |
||
| 51 | $query->whereNotIn('categories.id', array_filter((array) $filters['categories_exclude'])); |
||
| 52 | }); |
||
| 53 | } |
||
| 54 | |||
| 55 | if ($filters['exclude'] !== null) { |
||
| 56 | $data = $data->whereNotIn('id', array_filter((array) $filters['exclude'])); |
||
| 57 | } |
||
| 58 | |||
| 59 | if ($filters['include'] !== null) { |
||
| 60 | $data = $data->whereNotIn('id', array_filter((array) $filters['include'])); |
||
| 61 | } |
||
| 62 | |||
| 63 | if ($filters['author'] !== null) { |
||
| 64 | $data = $data->whereIn('author_id', array_filter((array) $filters['author'])); |
||
| 65 | } |
||
| 66 | |||
| 67 | if ($filters['author_exclude'] !== null) { |
||
| 68 | $data = $data->whereNotIn('author_id', array_filter((array) $filters['author_exclude'])); |
||
| 69 | } |
||
| 70 | |||
| 71 | if ($filters['featured'] !== null) { |
||
| 72 | $data = $data->where('is_featured', $filters['featured']); |
||
| 73 | } |
||
| 74 | |||
| 75 | if ($filters['search'] !== null) { |
||
| 76 | $keyword = isset($filters['search']) ? (string) $filters['search'] : null; |
||
| 77 | $data = $this->search($data, $keyword); |
||
|
|
|||
| 78 | } |
||
| 79 | |||
| 80 | $orderBy = Arr::get($filters, 'order_by', 'updated_at'); |
||
| 81 | $order = Arr::get($filters, 'order', 'desc'); |
||
| 82 | |||
| 83 | $data = $data |
||
| 84 | ->wherePublished() |
||
| 85 | ->orderBy($orderBy, $order); |
||
| 86 | |||
| 87 | return $data->paginate((int) $filters['per_page']); |
||
| 88 | } |
||
| 134 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.