Passed
Pull Request — main (#62)
by Tan
03:17
created

AuthorResource::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace CSlant\Blog\Api\Http\Resources\Author;
4
5
use CSlant\Blog\Core\Models\User;
6
use Illuminate\Http\Resources\Json\JsonResource;
7
8
/**
9
 * @mixin User
10
 */
11
class AuthorResource extends JsonResource
12
{
13
    /**
14
     * @param $request
15
     *
16
     * @return array<string, mixed>
17
     */
18
    public function toArray($request): array
19
    {
20
        /** @var User $this */
21
22
        return [
23
            'id' => $this->id,
24
            'first_name' => $this->first_name,
25
            'last_name' => $this->last_name,
26
            'image' => $this->avatar_url,
27
            'role' => $this->roles?->first()->name ?? null,
28
        ];
29
    }
30
}
31