Passed
Pull Request — main (#80)
by
unknown
03:17 queued 18s
created

ListCommentResourceCollection   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 15 1
1
<?php
2
3
namespace CSlant\Blog\Api\Http\Resources\Comment;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Http\Resources\Json\ResourceCollection;
7
use Illuminate\Pagination\LengthAwarePaginator;
8
9
class ListCommentResourceCollection extends ResourceCollection
10
{
11
    /**
12
     * The resource that this resource collects.
13
     *
14
     * @var string
15
     */
16
    public $collects = ListCommentResource::class;
17
18
    /**
19
     * Transform the resource collection into an array.
20
     *
21
     * @param  Request  $request
22
     *
23
     * @return array<string, mixed>
24
     */
25
    public function toArray(Request $request): array
26
    {
27
        /** @var LengthAwarePaginator<int, ListCommentResource> $paginator */
28
        $paginator = $this->resource;
29
30
        return [
31
            'data' => $this->collection,
32
            'meta' => [
33
                'current_page' => $paginator->currentPage(),
34
                'from' => $paginator->firstItem(),
35
                'last_page' => $paginator->lastPage(),
36
                'path' => $paginator->path(),
37
                'per_page' => $paginator->perPage(),
38
                'to' => $paginator->lastItem(),
39
                'total' => $paginator->total(),
40
            ],
41
        ];
42
    }
43
}
44