Passed
Pull Request — master (#28)
by Mike
02:21
created

CacheTagable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A makeCacheTags() 0 23 3
1
<?php namespace GeneaLabs\LaravelModelCaching\Traits;
2
3
use Illuminate\Database\Eloquent\Relations\Relation;
4
5
trait CacheTagable
6
{
7
    public function makeCacheTags() : array
8
    {
9
        return collect($this->eagerLoad)
0 ignored issues
show
Bug Best Practice introduced by
The property eagerLoad does not exist on GeneaLabs\LaravelModelCaching\Traits\CacheTagable. Did you maybe forget to declare it?
Loading history...
10
            ->keys()
11
            ->map(function ($relationName) {
12
                $relation = collect(explode('.', $relationName))
13
                    ->reduce(function ($carry, $name) {
14
                        if (! $carry) {
15
                            $carry = $this->model;
0 ignored issues
show
Bug Best Practice introduced by
The property model does not exist on GeneaLabs\LaravelModelCaching\Traits\CacheTagable. Did you maybe forget to declare it?
Loading history...
16
                        }
17
18
                        if ($carry instanceof Relation) {
19
                            $carry = $carry->getQuery()->model;
20
                        }
21
22
                        return $carry->{$name}();
23
                    });
24
25
                return str_slug(get_class($relation->getQuery()->model));
26
            })
27
            ->prepend(str_slug(get_class($this->model)))
0 ignored issues
show
Bug Best Practice introduced by
The property model does not exist on GeneaLabs\LaravelModelCaching\Traits\CacheTagable. Did you maybe forget to declare it?
Loading history...
28
            ->values()
29
            ->toArray();
30
    }
31
}
32