CacheResponse   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 9
c 1
b 0
f 0
dl 0
loc 55
ccs 11
cts 11
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCacheStore() 0 7 2
A setCacheStore() 0 5 1
A getDefaultCacheDriver() 0 3 1
A cacheKey() 0 3 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 22
    public function getCacheStore()
21
    {
22 22
        if ($this->cacheStore instanceof CacheStoreImp) {
23 12
            return $this->cacheStore;
24
        }
25
26 19
        return $this->cacheStore = $this->getDefaultCacheDriver();
27
    }
28
29
    /**
30
     * @return CacheStore
31
     *
32
     * @author duc <[email protected]>
33
     */
34 19
    public function getDefaultCacheDriver()
35
    {
36 19
        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
    /**
54
     * @param string $name
55
     * @param string $ip
56
     * @return string
57
     *
58
     * @author duc <[email protected]>
59
     */
60 15
    public function cacheKey(string $name, string $ip)
61
    {
62 15
        return $name . ':' . $ip;
63
    }
64
}
65