InertiaPaginatedResource   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 25
ccs 0
cts 9
cp 0
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 10 1
A __construct() 0 9 2
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