ListCategoryResource   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 12 3
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