CommentResource   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 14 2
1
<?php
2
3
namespace CSlant\Blog\Api\Http\Resources\Comment;
4
5
use CSlant\Blog\Api\Http\Resources\Author\AuthorResource;
6
use CSlant\Blog\Core\Models\Comment;
7
use Illuminate\Http\Request;
8
use Illuminate\Http\Resources\Json\JsonResource;
9
use Illuminate\Support\Facades\Auth;
10
11
/**
12
 * @mixin Comment
13
 */
14
class CommentResource extends JsonResource
15
{
16
    /**
17
     * @param  Request  $request
18
     *
19
     * @return array<string, mixed>
20
     */
21
    public function toArray(Request $request): array
22
    {
23
        $userId = Auth::user() ? Auth::user()->id : 0;
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
24
25
        /** @var Comment $this */
26
        return [
27
            'id' => $this->id,
28
            'website' => $this->website,
29
            'content' => $this->content,
30
            'status' => $this->status,
31
            'author' => AuthorResource::make($this->author),
32
            'replies' => CommentResource::collection($this->replies),
33
            'likes_count' => $this->likesCountDigital(),
34
            'is_liked' => $this->isLikedBy($userId),
35
        ];
36
    }
37
}
38