Passed
Pull Request — main (#1)
by Mohammad
02:54
created

CachePerRequest::__call()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 8
c 1
b 0
f 1
nc 3
nop 2
dl 0
loc 18
rs 10
1
<?php
2
3
namespace Shamaseen\Repository\Utility\Models;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Psr\SimpleCache\InvalidArgumentException;
7
8
trait CachePerRequest
9
{
10
    public bool $requestCacheEnabled = true;
11
    public RequestCache $requestCache;
12
13
    public function __construct(array $attributes = [])
14
    {
15
        $this->requestCache = new RequestCache($this->getRequestCacheKey());
16
        parent::__construct($attributes);
17
    }
18
19
    public function scopeDisableCache(Builder $query): Builder
20
    {
21
        $this->requestCacheEnabled = false;
22
23
        return $query;
24
    }
25
26
    public function scopeEnableCache(Builder $query): Builder
27
    {
28
        $this->requestCacheEnabled = true;
29
30
        return $query;
31
    }
32
33
    /**
34
     * @throws InvalidArgumentException
35
     */
36
    public function scopeClearCache(Builder $query): Builder
37
    {
38
        $this->requestCache->clear();
39
40
        return $query;
41
    }
42
43
    public function getRequestCacheKey(): string
44
    {
45
        return 'repository-cache';
46
    }
47
48
    public function getConnection()
49
    {
50
        return new ConnectionProxy(static::resolveConnection($this->getConnectionName()), $this);
0 ignored issues
show
Bug introduced by
The method getConnectionName() does not exist on Shamaseen\Repository\Uti...\Models\CachePerRequest. Did you maybe mean getConnection()? ( Ignorable by Annotation )

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

50
        return new ConnectionProxy(static::resolveConnection($this->/** @scrutinizer ignore-call */ getConnectionName()), $this);

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...
51
    }
52
}
53