Passed
Push — master ( 1992f4...72716e )
by Mike
02:16
created

Builder::eagerLoadRelation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 3
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
1
<?php namespace GeneaLabs\LaravelModelCaching;
2
3
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
4
5
class Builder extends EloquentBuilder
6
{
7
    protected function eagerLoadRelation(array $models, $name, Closure $constraints)
0 ignored issues
show
Bug introduced by
The type GeneaLabs\LaravelModelCaching\Closure was not found. Did you mean Closure? If so, make sure to prefix the type with \.
Loading history...
8
    {
9
        $relation = $this->getRelation($name);
10
        $relation->addEagerConstraints($models);
11
        $constraints($relation);
12
13
        $parentName = str_slug(get_class($relation->getParent()));
14
        $childName = str_slug(get_class($relation->getModel()));
15
        $results = cache()->tags([$parentName, $childName])
16
            ->rememberForever("{$parentName}-{$childName}-relation", function () use ($relation) {
17
                return $relation->getEager();
18
            });
19
20
        return $relation->match(
21
            $relation->initRelation($models, $name),
22
            $results,
23
            $name
24
        );
25
    }
26
}
27