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

HasMeta::collection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 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