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

ListCategoryResource::toArray()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 4
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace CSlant\Blog\Api\Http\Resources\Category;
4
5
use CSlant\Blog\Core\Facades\Base\BaseHelper;
6
use CSlant\Blog\Core\Http\Resources\Base\BaseListCategoryResource;
7
use CSlant\Blog\Core\Models\Category;
8
use CSlant\Blog\Core\Models\Slug;
9
use Illuminate\Http\Request;
10
11
/**
12
 * @method static mixed make(...$params)
13
 *
14
 * @mixin Category
15
 */
16
class ListCategoryResource extends BaseListCategoryResource
17
{
18
    /**
19
     * @param  Request  $request
20
     *
21
     * @return array<string, mixed>
22
     */
23
    public function toArray($request): array
24
    {
25
        /** @var Category $this */
26
        return [
27
            'id' => $this->id,
28
            'name' => $this->name,
29
            '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...
30
            'icon' => $this->icon ? BaseHelper::renderIcon($this->icon) : null,
31
            'description' => $this->description,
32
            'children' => CategoryResource::collection($this->children),
33
            'parent' => new CategoryResource($this->parent),
34
        ];
35
    }
36
}
37