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

ListCommentResourceCollection::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 15
rs 9.9
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