Test Setup Failed
Push — master ( d18a68...cd59fd )
by Gabriel
04:36
created

Cache   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A load() 0 8 2
A save() 0 6 1
1
<?php
2
3
namespace Nip\Filesystem;
4
5
use Psr\SimpleCache\CacheInterface;
6
use League\Flysystem\Cached\Storage\AbstractCache;
7
8
/**
9
 * Class Cache
10
 * @package Nip\Filesystem
11
 */
12
class Cache extends AbstractCache
13
{
14
    /**
15
     * The cache repository implementation.
16
     *
17
     * @var \Psr\SimpleCache\CacheInterface
18
     */
19
    protected $repository;
20
21
    /**
22
     * The cache key.
23
     *
24
     * @var string
25
     */
26
    protected $key;
27
28
    /**
29
     * The cache expiration time in seconds.
30
     *
31
     * @var int|null
32
     */
33
    protected $expire;
34
35
    /**
36
     * Create a new cache instance.
37
     *
38
     * @param \Psr\SimpleCache\CacheInterface $repository
39
     * @param string $key
40
     * @param int|null $expire
41
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
42
     */
43
    public function __construct(CacheInterface $repository, $key = 'flysystem', $expire = null)
44
    {
45
        $this->key = $key;
46
        $this->expire = $expire;
47
        $this->repository = $repository;
48
    }
49
50
    /**
51
     * Load the cache.
52
     *
53
     * @return void
54
     */
55
    public function load()
56
    {
57
        $contents = $this->repository->get($this->key);
58
59
        if (!is_null($contents)) {
60
            $this->setFromStorage($contents);
61
        }
62
    }
63
64
    /**
65
     * Persist the cache.
66
     *
67
     * @return void
68
     */
69
    public function save()
70
    {
71
        $contents = $this->getForStorage();
72
73
        $this->repository->set($this->key, $contents, $this->expire);
74
    }
75
}