AuthorResource::toArray()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 10
c 1
b 0
f 1
nc 4
nop 1
dl 0
loc 13
rs 9.9332
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
        return [
22
            'id' => $this->id,
23
            'first_name' => $this->first_name,
24
            'last_name' => $this->last_name,
25
            'username' => $this->username,
26
            'full_name' => $this->first_name && $this->last_name
27
                ? $this->first_name . ' ' . $this->last_name
28
                : ($this->first_name ?? $this->last_name ?? 'Base Member'),
29
            'image' => $this->avatar_url,
30
            'role' => $this->roles?->first()->name ?? null,
31
        ];
32
    }
33
}
34