ListCategoryResource::toArray()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 4
nop 1
dl 0
loc 12
rs 9.9666
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\Models\Category;
7
use CSlant\Blog\Core\Models\Slug;
8
use Illuminate\Http\Request;
9
use Illuminate\Http\Resources\Json\JsonResource;
10
11
/**
12
 * @method static mixed make(...$params)
13
 *
14
 * @mixin Category
15
 */
16
class ListCategoryResource extends JsonResource
17
{
18
    /**
19
     * @param  Request  $request
20
     *
21
     * @return array<string, mixed>
22
     */
23
    public function toArray(Request $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
            'posts_count' => $this->posts_count,
35
        ];
36
    }
37
}
38