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

ListPostResource::toArray()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 4
nop 1
dl 0
loc 14
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace CSlant\Blog\Api\Http\Resources\Post;
4
5
use CSlant\Blog\Api\Http\Resources\Author\AuthorResource;
6
use CSlant\Blog\Api\Http\Resources\Category\CategoryResource;
7
use CSlant\Blog\Api\Http\Resources\Tag\TagResource;
8
use CSlant\Blog\Core\Facades\Base\Media\RvMedia;
9
use CSlant\Blog\Core\Http\Resources\Base\BaseListPostResource;
10
use CSlant\Blog\Core\Models\Post;
11
use CSlant\Blog\Core\Models\Slug;
12
use Illuminate\Http\Request;
13
14
/**
15
 * @mixin Post
16
 */
17
class ListPostResource extends BaseListPostResource
18
{
19
    /**
20
     * @param  Request  $request
21
     *
22
     * @return array<string, mixed>
23
     */
24
    public function toArray($request): array
25
    {
26
        /** @var Post $this */
27
        return [
28
            'id' => $this->id,
29
            'name' => $this->name,
30
            'slug' => $this->slug instanceof Slug ? $this->slug->key : $this->slug,
0 ignored issues
show
introduced by
$this->slug is always a sub-type of CSlant\Blog\Core\Models\Slug.
Loading history...
31
            'description' => $this->description,
32
            'image' => $this->image ? RvMedia::url($this->image) : null,
33
            'categories' => CategoryResource::collection($this->categories),
34
            'tags' => TagResource::collection($this->tags),
35
            'author' => AuthorResource::make($this->author),
36
            'created_at' => $this->created_at,
37
            'updated_at' => $this->updated_at,
38
        ];
39
    }
40
}
41