Completed
Branch master (62cc10)
by Tyler
02:58
created

AutoCache   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 32
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A newEloquentBuilder() 0 4 1
A refresh() 0 6 1
1
<?php
2
3
namespace Tylercd100\Database\Eloquent\Traits;
4
5
use Tylercd100\Database\Eloquent\Builder;
6
use Illuminate\Support\Facades\Cache;
7
8
trait AutoCache
9
{
10
    /**
11
     * Set the cache expiry time.
12
     *
13
     * @var int
14
     */
15
    public $cacheExpiry = 1440;
16
17
    /**
18
     * Create a new Eloquent query builder for the model.
19
     *
20
     * @param  \Illuminate\Database\Query\Builder $query
21
     * @return \PulkitJalan\Cacheable\Eloquent\Builder|static
22
     */
23
    public function newEloquentBuilder($query)
24
    {
25
        return new Builder($query);
26
    }
27
28
    /**
29
     * Refresh the current models cache.
30
     *
31
     * @return $this
32
     */
33
    public function refresh()
34
    {
35
        Cache::tags($this->getTable())->forget($this->{$this->getKeyName()});
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...
Bug introduced by
It seems like getKeyName() 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...
36
37
        return $this;
38
    }
39
}
40