Completed
Push — master ( b01d16...d9d1e2 )
by Ruben
03:30
created

HasMeta   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 35
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A collection() 0 12 2
A make() 0 4 1
A mergeCollectionEndpoints() 0 6 1
A meta() 0 4 1
1
<?php
2
3
namespace Spatie\ResourceLinks;
4
5
/** @mixin \Illuminate\Http\Resources\Json\JsonResource */
6
trait HasMeta
7
{
8
    /** @var bool  */
9
    private $mergeCollectionEndpoints = false;
10
11
    public static function collection($resource)
12
    {
13
        $meta = self::meta();
14
15
        if (! count($meta)) {
16
            parent::collection($resource);
17
        }
18
19
        return parent::collection($resource)->additional([
20
            'meta' => $meta,
21
        ]);
22
    }
23
24
    public static function make(...$parameters)
25
    {
26
        return parent::make(...$parameters)->mergeCollectionEndpoints();
27
    }
28
29
    public function mergeCollectionEndpoints()
30
    {
31
        $this->mergeCollectionEndpoints = true;
32
33
        return $this;
34
    }
35
36
    public static function meta()
37
    {
38
        return [];
39
    }
40
}
41