Completed
Push — master ( 54527b...d7d176 )
by Richan
01:11
created

CacheableTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A bootCacheableTrait() 0 4 1
A cacheTags() 0 8 2
1
<?php
2
3
namespace Suitmedia\Cacheable\Traits\Model;
4
5
use Suitmedia\Cacheable\CacheableObserver;
6
7
trait CacheableTrait
8
{
9
    /**
10
     * Boot the Cacheable trait by attaching
11
     * a new observer to the current model.
12
     *
13
     * @return void
14
     */
15
    public static function bootCacheableTrait()
16
    {
17
        static::observe(app(CacheableObserver::class));
18
    }
19
20
    /**
21
     * Generate cache tags automatically
22
     * based on the model class name.
23
     *
24
     * @return string|array
25
     */
26
    public function cacheTags()
27
    {
28
        if (property_exists($this, 'cacheTags')) {
29
            return (array) static::$cacheTags;
30
        }
31
32
        return class_basename(get_class($this));
33
    }
34
}
35