Passed
Pull Request — master (#97)
by
unknown
02:19
created

QueryOrModelCaller   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __call() 0 10 2
1
<?php
2
3
namespace GeneaLabs\LaravelModelCaching;
4
5
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
6
use Illuminate\Database\Eloquent\Model;
7
8
class QueryOrModelCaller
9
{
10
    /**
11
     * @var CachedBuilder
12
     */
13
    protected $query;
14
    /**
15
     * @var Model
16
     */
17
    protected $model;
18
    /**
19
     * @var bool
20
     */
21
    protected $disableInConfig;
22
23
    /**
24
     * QueryOrModelCaller constructor.
25
     *
26
     * @param EloquentBuilder $query
27
     * @param Model           $model
28
     * @param bool            $disableInConfig
29
     */
30
    public function __construct(EloquentBuilder $query, Model $model, bool $disableInConfig)
31
    {
32
        $this->query = $query;
0 ignored issues
show
Documentation Bug introduced by
$query is of type Illuminate\Database\Eloquent\Builder, but the property $query was declared to be of type GeneaLabs\LaravelModelCaching\CachedBuilder. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
33
        $this->model = $model;
34
        $this->disableInConfig = $disableInConfig;
35
    }
36
37
    /**
38
     * @param $name
39
     * @param $arguments
40
     *
41
     * @return mixed
42
     */
43
    public function __call($name, $arguments)
44
    {
45
        if ($name == 'all')
46
            $result = call_user_func_array([$this->model, 'all'], $arguments);
47
        else
48
            $result = call_user_func_array([$this->query, $name], $arguments);
49
50
        config()->set('laravel-model-caching.disabled', $this->disableInConfig);
51
52
        return $result;
53
    }
54
}
55