CacheTrait::getCache()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipbox/hubspot/blob/master/LICENSE.md
6
 * @link       https://github.com/flipbox/hubspot
7
 */
8
9
namespace Flipbox\HubSpot\Criteria;
10
11
use Flipbox\HubSpot\HubSpot;
12
use Psr\SimpleCache\CacheInterface;
13
14
/**
15
 * @author Flipbox Factory <[email protected]>
16
 * @since 2.0.0
17
 */
18
trait CacheTrait
19
{
20
    /**
21
     * @var CacheInterface|null
22
     */
23
    protected $cache;
24
25
    /**
26
     * @param $value
27
     * @return $this
28
     */
29
    public function cache($value)
30
    {
31
        return $this->setCache($value);
32
    }
33
34
    /**
35
     * @param $value
36
     * @return $this
37
     */
38
    public function setCache($value)
39
    {
40
        $this->cache = $value;
41
        return $this;
42
    }
43
44
    /**
45
     * @return CacheInterface
46
     */
47
    public function getCache(): CacheInterface
48
    {
49
        return $this->cache = $this->resolveCache($this->cache);
50
    }
51
52
    /**
53
     * @param $cache
54
     * @return CacheInterface
55
     */
56
    protected function resolveCache($cache): CacheInterface
57
    {
58
        if ($cache instanceof CacheInterface) {
59
            return $cache;
60
        }
61
62
        return HubSpot::getCache();
63
    }
64
}
65