Passed
Push — master ( 4a84e5...3893f1 )
by Mike
03:42
created

CachedBelongsToMany::getRelation()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 2
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php namespace GeneaLabs\LaravelModelCaching;
2
3
use GeneaLabs\LaravelPivotEvents\Traits\FiresPivotEventsTrait;
4
use GeneaLabs\LaravelModelCaching\Traits\Buildable;
5
use GeneaLabs\LaravelModelCaching\Traits\BuilderCaching;
6
use GeneaLabs\LaravelModelCaching\Traits\Caching;
7
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
8
9
class CachedBelongsToMany extends BelongsToMany
10
{
11
    use Buildable;
12
    use BuilderCaching;
13
    use Caching;
14
    use FiresPivotEventsTrait;
15
16
    public function getRelation($name)
17
    {
18
        $relation = parent::getRelation($name);
0 ignored issues
show
Bug introduced by
The method getRelation() does not exist on Illuminate\Database\Eloq...Relations\BelongsToMany. Did you maybe mean getRelationCountHash()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
        /** @scrutinizer ignore-call */ 
19
        $relation = parent::getRelation($name);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
19
20
        if (! $this->isCachable()
21
            && is_a($relation->getQuery(), self::class)
22
        ) {
23
            $relation->getQuery()->disableModelCaching();
24
        }
25
26
        return $relation;
27
    }
28
}
29