Passed
Pull Request — main (#62)
by Tan
04:09 queued 01:22
created

PostResource::toArray()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 4
nop 1
dl 0
loc 14
rs 9.8666
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\Models\Post;
10
use CSlant\Blog\Core\Models\Slug;
11
use Illuminate\Http\Resources\Json\JsonResource;
12
13
/**
14
 * @mixin Post
15
 */
16
class PostResource extends JsonResource
17
{
18
    /**
19
     * @param $request
20
     *
21
     * @return array<string, mixed>
22
     */
23
    public function toArray($request): array
24
    {
25
        return [
26
            'id' => $this->id,
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist on CSlant\Blog\Api\Http\Resources\Post\PostResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
27
            'name' => $this->name,
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on CSlant\Blog\Api\Http\Resources\Post\PostResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
28
            'slug' => $this->slug instanceof Slug ? $this->slug->key : $this->slug,
0 ignored issues
show
Bug Best Practice introduced by
The property slug does not exist on CSlant\Blog\Api\Http\Resources\Post\PostResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
29
            'description' => $this->description,
0 ignored issues
show
Bug Best Practice introduced by
The property description does not exist on CSlant\Blog\Api\Http\Resources\Post\PostResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
30
            'content' => $this->content,
0 ignored issues
show
Bug Best Practice introduced by
The property content does not exist on CSlant\Blog\Api\Http\Resources\Post\PostResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
31
            'image' => $this->image ? RvMedia::url($this->image) : null,
0 ignored issues
show
Bug Best Practice introduced by
The property image does not exist on CSlant\Blog\Api\Http\Resources\Post\PostResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
32
            'categories' => CategoryResource::collection($this->categories),
0 ignored issues
show
Bug Best Practice introduced by
The property categories does not exist on CSlant\Blog\Api\Http\Resources\Post\PostResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
33
            'tags' => TagResource::collection($this->tags),
0 ignored issues
show
Bug Best Practice introduced by
The property tags does not exist on CSlant\Blog\Api\Http\Resources\Post\PostResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
34
            'author' => AuthorResource::make($this->author),
0 ignored issues
show
Bug Best Practice introduced by
The property author does not exist on CSlant\Blog\Api\Http\Resources\Post\PostResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
35
            'created_at' => $this->created_at,
0 ignored issues
show
Bug Best Practice introduced by
The property created_at does not exist on CSlant\Blog\Api\Http\Resources\Post\PostResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
36
            'updated_at' => $this->updated_at,
0 ignored issues
show
Bug Best Practice introduced by
The property updated_at does not exist on CSlant\Blog\Api\Http\Resources\Post\PostResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
37
        ];
38
    }
39
}
40