Passed
Push — master ( 37d7ff...4e50f6 )
by du
01:47
created

CacheResponse::setCacheStore()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace DucCnzj\Ip\Traits;
4
5
use DucCnzj\Ip\CacheStore;
6
use DucCnzj\Ip\Imp\CacheStoreImp;
7
8
trait CacheResponse
9
{
10
    /**
11
     * @var null|CacheStoreImp
12
     */
13
    protected $cacheStore;
14
15
    /**
16
     * @return CacheStore|CacheStoreImp
17
     *
18
     * @author duc <[email protected]>
19
     */
20 17
    public function getCacheStore()
21
    {
22 17
        if ($this->cacheStore instanceof CacheStoreImp) {
23 10
            return $this->cacheStore;
24
        }
25
26 14
        return $this->cacheStore = $this->getDefaultCacheDriver();
27
    }
28
29
    /**
30
     * @return CacheStore
31
     *
32
     * @author duc <[email protected]>
33
     */
34 14
    public function getDefaultCacheDriver()
35
    {
36 14
        return new CacheStore();
37
    }
38
39
    /**
40
     * @param CacheStoreImp $cacheStore
41
     *
42
     * @return $this
43
     *
44
     * @author duc <[email protected]>
45
     */
46 3
    public function setCacheStore(CacheStoreImp $cacheStore)
47
    {
48 3
        $this->cacheStore = $cacheStore;
49
50 3
        return $this;
51
    }
52
53 10
    public function cacheKey(string $name, string $ip)
54
    {
55 10
        return $name . ':' . $ip;
56
    }
57
}
58