AuthorService   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 4
Bugs 1 Features 2
Metric Value
eloc 7
c 4
b 1
f 2
dl 0
loc 22
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getAllAuthor() 0 13 1
1
<?php
2
3
namespace CSlant\Blog\Api\Services;
4
5
use CSlant\Blog\Core\Http\Responses\Base\BaseHttpResponse;
6
use CSlant\Blog\Core\Models\User;
7
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
8
use Illuminate\Database\Eloquent\Model;
9
use Illuminate\Support\Arr;
10
11
/**
12
 * Class AuthorService
13
 *
14
 * @package CSlant\Blog\Api\Services
15
 *
16
 * @method BaseHttpResponse httpResponse()
17
 */
18
class AuthorService
19
{
20
    /**
21
     * Get all author.
22
     *
23
     * @param  array<string, mixed>  $filters
24
     *
25
     * @return LengthAwarePaginator<int, Model>
26
     */
27
    public function getAllAuthor(array $filters): LengthAwarePaginator
28
    {
29
        /** @var User $data */
30
        $data = User::query()->withCount('posts');
31
32
        $data = $data->where('super_user', $filters['is_super']);
33
34
        $data = $data->orderBy(
35
            Arr::get($filters, 'order_by', 'posts_count'),
36
            Arr::get($filters, 'order', 'desc')
37
        );
38
39
        return $data->paginate($filters['per_page']);
40
    }
41
}
42