ListPostResourceCollection::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 2 Features 1
Metric Value
cc 1
eloc 10
c 3
b 2
f 1
nc 1
nop 1
dl 0
loc 15
rs 9.9332
1
<?php
2
3
namespace CSlant\Blog\Api\Http\Resources\Post;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Http\Resources\Json\ResourceCollection;
7
use Illuminate\Pagination\LengthAwarePaginator;
8
9
class ListPostResourceCollection extends ResourceCollection
10
{
11
    /**
12
     * The resource that this resource collects.
13
     *
14
     * @var string
15
     */
16
    public $collects = ListPostResource::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, ListPostResource> $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