AuthorWithPostResource   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 15 1
1
<?php
2
3
namespace CSlant\Blog\Api\Http\Resources\Author;
4
5
use CSlant\Blog\Api\Http\Resources\Post\ListPostResourceCollection;
6
use CSlant\Blog\Core\Models\User;
7
use Illuminate\Http\Resources\Json\JsonResource;
8
9
/**
10
 * @mixin User
11
 */
12
class AuthorWithPostResource extends JsonResource
13
{
14
    /**
15
     * @param $request
16
     *
17
     * @return array<string, mixed>
18
     */
19
    public function toArray($request): array
20
    {
21
        /** @var User $this */
22
        $posts = $this->posts()
23
            ->orderBy((string) $request->get('order_by', 'created_at'), (string) $request->get('order', 'DESC'))
24
            ->paginate($request->integer('per_page', 10));
25
26
        return [
27
            'id' => $this->id,
28
            'email' => $this->email,
29
            'first_name' => $this->first_name,
30
            'last_name' => $this->last_name,
31
            'username' => $this->username,
32
            'image' => $this->avatar_url,
33
            'posts' => ListPostResourceCollection::make($posts),
34
        ];
35
    }
36
}
37