ZendStorageCache   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 33
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A load() 0 8 2
A save() 0 5 1
1
<?php
2
3
/**
4
 * BsbFlystem
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @see       https://bushbaby.nl/
10
 *
11
 * @copyright Copyright (c) 2014-2021 bushbaby multimedia. (https://bushbaby.nl)
12
 * @author    Bas Kamer <[email protected]>
13
 * @license   MIT
14
 *
15
 * @package   bushbaby/flysystem
16
 */
17
18
declare(strict_types=1);
19
20
namespace BsbFlysystem\Cache;
21
22
use Laminas\Cache\Storage\StorageInterface;
23
use League\Flysystem\Cached\Storage\AbstractCache;
24
25 7
/**
26
 * Wrapper class that allows usage of a Zend Cache as a Flysystem Cache.
27 7
 */
28 7
class ZendStorageCache extends AbstractCache
29 7
{
30
    /**
31 5
     * @var string storage key
32
     */
33 5
    protected $key;
34
35 5
    /**
36 1
     * @var StorageInterface
37
     */
38 5
    protected $storage;
39
40 2
    public function __construct(StorageInterface $storage, string $key = 'bsbflysystem')
41
    {
42 2
        $this->storage = $storage;
43 2
        $this->key = $key;
44 2
    }
45
46
    public function load(): void
47
    {
48
        $contents = $this->storage->getItem($this->key);
49
50
        if (null !== $contents) {
51
            $this->setFromStorage($contents);
52
        }
53
    }
54
55
    public function save(): void
56
    {
57
        $contents = $this->getForStorage();
58
        $this->storage->setItem($this->key, $contents);
59
    }
60
}
61