Stash::save()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1.0046

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 6
cp 0.8333
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1.0046
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