Stash   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 85%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 54
ccs 17
cts 20
cp 0.85
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A load() 0 9 2
A save() 0 6 1
1
<?php
2
3
namespace League\Flysystem\Cached\Storage;
4
5
use Stash\Pool;
6
7
class Stash extends AbstractCache
8
{
9
    /**
10
     * @var string storage key
11
     */
12
    protected $key;
13
14
    /**
15
     * @var int|null seconds until cache expiration
16
     */
17
    protected $expire;
18
19
    /**
20
     * @var \Stash\Pool Stash pool instance
21
     */
22
    protected $pool;
23
24
    /**
25
     * Constructor.
26
     *
27
     * @param \Stash\Pool $pool
28
     * @param string      $key    storage key
29
     * @param int|null    $expire seconds until cache expiration
30
     */
31 9
    public function __construct(Pool $pool, $key = 'flysystem', $expire = null)
32
    {
33 9
        $this->key = $key;
34 9
        $this->expire = $expire;
35 9
        $this->pool = $pool;
36 9
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 6
    public function load()
42
    {
43 6
        $item = $this->pool->getItem($this->key);
44 6
        $contents = $item->get();
45
46 6
        if ($item->isMiss() === false) {
47 3
            $this->setFromStorage($contents);
48 3
        }
49 6
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 3
    public function save()
55
    {
56 3
        $contents = $this->getForStorage();
57 3
        $item = $this->pool->getItem($this->key);
58 3
        $item->set($contents, $this->expire);
59 3
    }
60
}
61