GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

IsCacheable::newBaseQueryBuilder()   B
last analyzed

Complexity

Conditions 6
Paths 15

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
c 0
b 0
f 0
rs 8.7537
cc 6
nc 15
nop 0
1
<?php
2
3
namespace Neurony\QueryCache\Traits;
4
5
use Illuminate\Database\Query\Builder;
6
use Neurony\QueryCache\Database\QueryCacheBuilder;
7
8
trait IsCacheable
9
{
10
    /**
11
     * Boot the model.
12
     *
13
     * @return void
14
     */
15
    public static function bootIsCacheable()
16
    {
17
        static::saved(function ($model) {
18
            $model->clearQueryCache();
19
        });
20
21
        static::deleted(function ($model) {
22
            $model->clearQueryCache();
23
        });
24
    }
25
26
    /**
27
     * @return string
28
     */
29
    public function getQueryCacheTag(): string
30
    {
31
        return app('cache.query')->getAllQueryCachePrefix().'.'.(string) $this->getTable();
0 ignored issues
show
Bug introduced by
It seems like getTable() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
32
    }
33
34
    /**
35
     * @return string
36
     */
37
    public function getDuplicateQueryCacheTag(): string
38
    {
39
        return app('cache.query')->getDuplicateQueryCachePrefix().'.'.(string) $this->getTable();
0 ignored issues
show
Bug introduced by
It seems like getTable() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
40
    }
41
42
    /**
43
     * Flush the query cache from Redis only for the tag corresponding to the model instance.
44
     *
45
     * @return void
46
     */
47
    public function clearQueryCache(): void
48
    {
49
        app('cache.query')->clearQueryCache($this);
50
    }
51
52
    /**
53
     * Get a new query builder instance for the connection.
54
     *
55
     * @return Builder
56
     */
57
    protected function newBaseQueryBuilder(): Builder
58
    {
59
        $cacheAllQueriesForever = false;
60
        $cacheOnlyDuplicateQueriesOnce = false;
61
62
        $connection = $this->getConnection();
0 ignored issues
show
Bug introduced by
It seems like getConnection() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
63
        $grammar = $connection->getQueryGrammar();
64
65
        if (app('cache.query')->canCacheQueries()) {
66
            if (app('cache.query')->shouldCacheAllQueries()) {
67
                $cacheAllQueriesForever = true;
68
            }
69
70
            if (app('cache.query')->shouldCacheDuplicateQueries()) {
71
                $cacheOnlyDuplicateQueriesOnce = true;
72
            }
73
        }
74
75
        if ($cacheAllQueriesForever === true) {
76
            return new QueryCacheBuilder(
77
                $connection, $grammar, $connection->getPostProcessor(),
78
                $this->getQueryCacheTag(), app('cache.query')->cacheAllQueriesForeverType()
79
            );
80
        }
81
82
        if ($cacheOnlyDuplicateQueriesOnce === true) {
83
            return new QueryCacheBuilder(
84
                $connection, $grammar, $connection->getPostProcessor(),
85
                $this->getDuplicateQueryCacheTag(), app('cache.query')->cacheOnlyDuplicateQueriesOnceType()
86
            );
87
        }
88
89
        return parent::newBaseQueryBuilder();
90
    }
91
}
92