Passed
Pull Request — main (#99)
by Tan
03:05
created

PostNavigationResource   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 16 3
1
<?php
2
3
namespace CSlant\Blog\Api\Http\Resources\Post;
4
5
use CSlant\Blog\Core\Facades\Base\Media\RvMedia;
6
use CSlant\Blog\Core\Models\Post;
7
use Illuminate\Http\Request;
8
use Illuminate\Http\Resources\Json\JsonResource;
9
10
/**
11
 * Post Navigation Resource for previous/next navigation
12
 */
13
class PostNavigationResource extends JsonResource
14
{
15
    /**
16
     * @param  Request  $request
17
     *
18
     * @return array<string, mixed>
19
     */
20
    public function toArray($request): array
21
    {
22
        if (!$this->resource) {
23
            return [];
24
        }
25
26
        /** @var Post $this */
27
        return [
28
            'id' => $this->id,
29
            'name' => $this->name,
30
            'description' => $this->description,
31
            'slug' => $this->slug,
32
            'url' => $this->url,
33
            'image' => $this->image ? RvMedia::getImageUrl($this->image) : null,
34
            'created_at' => $this->created_at,
35
            'updated_at' => $this->updated_at,
36
        ];
37
    }
38
}
39