Passed
Pull Request — main (#41)
by
unknown
05:07 queued 02:20
created

PostRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
c 1
b 0
f 1
dl 0
loc 27
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilters() 0 20 2
A __construct() 0 3 1
1
<?php
2
3
namespace CSlant\Blog\Core\Http\Repositories;
4
5
use Botble\Support\Repositories\Eloquent\RepositoriesAbstract;
0 ignored issues
show
Bug introduced by
The type Botble\Support\Repositor...nt\RepositoriesAbstract was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use CSlant\Blog\Core\Models\Post;
7
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
8
use Illuminate\Database\Eloquent\Builder;
9
use Illuminate\Support\Arr;
10
use Illuminate\Support\Collection;
11
12
class PostRepository extends RepositoriesAbstract
13
{
14
    public function __construct(Post $post)
15
    {
16
        parent::__construct($post);
17
    }
18
19
    public function getFilters(array $filters): Collection|LengthAwarePaginator
20
    {
21
        $data = $this->originalModel;
22
23
        if ($filters['tags'] !== null) {
24
            $tags = array_filter((array) $filters['tags']);
25
26
            $data = $data->whereHas('tags', function (Builder $query) use ($tags): void {
27
                $query->whereIn('tags.id', $tags);
28
            });
29
        }
30
31
        $orderBy = Arr::get($filters, 'order_by', 'updated_at');
32
        $order = Arr::get($filters, 'order', 'desc');
33
34
        $data = $data
35
            ->wherePublished()
36
            ->orderBy($orderBy, $order);
37
38
        return $this->applyBeforeExecuteQuery($data)->paginate((int) $filters['per_page']);
39
    }
40
}
41