BaseResource   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 10
c 2
b 0
f 1
dl 0
loc 33
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 9 1
A rejectNullValues() 0 4 2
1
<?php
2
3
namespace Laravel\DataTables\Resources;
4
5
use Illuminate\Http\Resources\Json\JsonResource;
6
use Illuminate\Support\Arr;
7
use Laravel\DataTables\Services\BaseDataTableService;
8
9
abstract class BaseResource extends JsonResource
10
{
11
    /**
12
     * @param BaseDatatableService $dataTable
13
     */
14
    abstract public function dataTable(): BaseDataTableService;
15
16
    /**
17
     * @param $resource
18
     */
19
    public function rejectNullValues($resource)
20
    {
21
        return array_filter($resource, function ($value) {
22
            return ! is_null($value) || ! empty($value);
23
        });
24
    }
25
26
    /**
27
     * @param $request
28
     */
29
30
    /**
31
     * @param $request
32
     */
33
    public function toArray($request)
34
    {
35
        return $this->rejectNullValues([
36
            'id' => $this->id,
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist on Laravel\DataTables\Resources\BaseResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
37
            'created_at_human' => optional($this->created_at)->diffForHumans(),
0 ignored issues
show
Bug Best Practice introduced by
The property created_at does not exist on Laravel\DataTables\Resources\BaseResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
38
            'updated_at_human' => optional($this->updated_at)->diffForHumans(),
0 ignored issues
show
Bug Best Practice introduced by
The property updated_at does not exist on Laravel\DataTables\Resources\BaseResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
39
        ] + Arr::only(
40
            $this->resource->toArray(),
41
            $this->dataTable()->getDisplayableColumns()
42
        ));
43
    }
44
}
45