InertiaPaginatedResource::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 9
ccs 0
cts 5
cp 0
crap 6
rs 10
1
<?php
2
3
namespace InertiaDashboardKit\Adapt\Resources;
4
5
use Illuminate\Http\Resources\Json\ResourceCollection;
6
use Illuminate\Support\Arr;
7
8
class InertiaPaginatedResource extends ResourceCollection
9
{
10
    protected array $mapOptions = [];
11
12
    public function __construct($resource, ?string $collects = null, array $mapOptions = [])
13
    {
14
        if ($collects) {
15
            $this->collects = $collects;
16
        }
17
18
        $this->mapOptions = $mapOptions;
19
20
        parent::__construct($resource);
21
    }
22
23
    public function toArray($request)
24
    {
25
        $meta = Arr::except($this->resource->toArray(), [
26
            'data',
27
        ]);
28
        $meta['links'] = array_slice($meta['links'], 1, -1);
29
30
        return [
31
            'data' => $this->collection->map->toArray($request, $this->mapOptions)->all(),
32
            'meta' => $meta,
33
        ];
34
    }
35
}
36