ListPostResourceCollection   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 3
Bugs 2 Features 1
Metric Value
eloc 12
c 3
b 2
f 1
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\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