Passed
Push — master ( 2173e1...800b2f )
by Mostafa
05:03 queued 02:26
created

LaraCache   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 5
c 1
b 0
f 0
dl 0
loc 29
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A cache() 0 3 1
A bootLaraCache() 0 3 1
A laraCache() 0 3 1
1
<?php
2
3
namespace Mostafaznv\LaraCache\Traits;
4
5
use Exception;
6
use Mostafaznv\LaraCache\Cache;
7
use Mostafaznv\LaraCache\CacheEntity;
8
use Mostafaznv\LaraCache\Observers\LaraCacheObserver;
9
10
/**
11
 * @mixin \Illuminate\Database\Eloquent\Model
12
 */
13
trait LaraCache
14
{
15
    public static bool $isEnabled = true;
16
17
    /**
18
     * Boot LaraCache
19
     *
20
     * @throws Exception
21
     */
22
    public static function bootLaraCache()
23
    {
24
        self::observe(LaraCacheObserver::class);
25
    }
26
27
    /**
28
     * Get the entities should store in cache
29
     *
30
     * @return CacheEntity[]
31
     */
32
    abstract static public function cacheEntities(): array;
33
34
    public static function cache(): Cache
35
    {
36
        return new Cache(self::class);
37
    }
38
39
    public static function laraCache(): Cache
40
    {
41
        return new Cache(self::class);
42
    }
43
}
44