Completed
Push — develop ( 0ca1ab...29c245 )
by Nate
03:14
created

CacheTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 43
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A cache() 0 4 1
A setCache() 0 5 1
A getCache() 0 12 3
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/hubspot/license
6
 * @link       https://www.flipboxfactory.com/software/hubspot/
7
 */
8
9
namespace flipbox\hubspot\criteria\traits;
10
11
use flipbox\hubspot\HubSpot;
12
use flipbox\hubspot\services\Cache;
13
use Psr\SimpleCache\CacheInterface;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
trait CacheTrait
20
{
21
    /**
22
     * @var CacheInterface|string|null
23
     */
24
    protected $cache = Cache::DEFAULT_CACHE;
25
26
    /**
27
     * @param $value
28
     * @return $this
29
     */
30
    public function cache($value)
31
    {
32
        return $this->setCache($value);
33
    }
34
35
    /**
36
     * @param $value
37
     * @return $this
38
     */
39
    public function setCache($value)
40
    {
41
        $this->cache = $value;
42
        return $this;
43
    }
44
45
    /**
46
     * @return CacheInterface
47
     * @throws \yii\base\InvalidConfigException
48
     */
49
    public function getCache(): CacheInterface
50
    {
51
        if ($this->cache instanceof CacheInterface) {
52
            return $this->cache;
53
        }
54
55
        if ($this->cache === null) {
56
            $this->cache = Cache::DEFAULT_CACHE;
57
        }
58
59
        return $this->cache = HubSpot::getInstance()->getCache()->get($this->cache);
60
    }
61
}
62