Completed
Push — develop ( b48ec5...ad5b3d )
by Nate
08:03
created

CacheHelper::resolveCache()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 10
cp 0
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 12
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\helpers;
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
class CacheHelper
20
{
21
    /**
22
     * @param string|CacheInterface $cache
23
     * @return CacheInterface
24
     * @throws \yii\base\InvalidConfigException
25
     */
26
    public static function resolveCache($cache): CacheInterface
27
    {
28
        if ($cache instanceof CacheInterface) {
29
            return $cache;
30
        }
31
32
        if ($cache === null) {
33
            $cache = Cache::DEFAULT_CACHE;
34
        }
35
36
        return HubSpot::getInstance()->getCache()->get($cache);
37
    }
38
}
39