Passed
Push — main ( 93a56b...1863f6 )
by Tan
11:12
created

ListPostResource   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 3
eloc 13
c 3
b 2
f 0
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A collection() 0 3 1
A toArray() 0 15 2
1
<?php
2
3
namespace CSlant\Blog\Api\Http\Resources;
4
5
use CSlant\Blog\Core\Facades\Base\Media\RvMedia;
6
use CSlant\Blog\Core\Http\Resources\Base\BaseListPostResource;
7
use CSlant\Blog\Core\Models\Post;
8
use Illuminate\Http\Request;
9
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
10
use Illuminate\Http\Resources\Json\JsonResource;
11
12
/**
13
 * @mixin Post
14
 */
15
class ListPostResource extends BaseListPostResource
16
{
17
    /**
18
     * @param  Request  $request
19
     *
20
     * @return array<string, mixed>
21
     */
22
    public function toArray($request): array
23
    {
24
        /** @var Post $this */
25
26
        return [
27
            'id' => $this->id,
28
            'name' => $this->name,
29
            'slug' => $this->slug,
30
            'description' => $this->description,
31
            'image' => $this->image ? RvMedia::url($this->image) : null,
32
            'categories' => CategoryResource::collection($this->categories),
33
            'tags' => TagResource::collection($this->tags),
34
            'author' => AuthorResource::make($this->author),
35
            'created_at' => $this->created_at,
36
            'updated_at' => $this->updated_at,
37
        ];
38
    }
39
40
    /**
41
     * @param  mixed  $resource
42
     *
43
     * @return AnonymousResourceCollection
44
     */
45
    public static function collection(mixed $resource): AnonymousResourceCollection
46
    {
47
        return JsonResource::collection($resource);
48
    }
49
}
50