Cache::load()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
use League\Flysystem\Cached\Storage\AbstractCache;
0 ignored issues
show
Bug introduced by
The type League\Flysystem\Cached\Storage\AbstractCache was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
5
use Psr\SimpleCache\CacheInterface;
6
7
/**
8
 * Class Cache
9
 * @package Nip\Filesystem
10
 */
11
class Cache extends AbstractCache
12
{
13
    /**
14
     * The cache repository implementation.
15
     *
16
     * @var \Psr\SimpleCache\CacheInterface
17
     */
18
    protected $repository;
19
20
    /**
21
     * The cache key.
22
     *
23
     * @var string
24
     */
25
    protected $key;
26
27
    /**
28
     * The cache expiration time in seconds.
29
     *
30
     * @var int|null
31
     */
32
    protected $expire;
33
34
    /**
35
     * Create a new cache instance.
36
     *
37
     * @param \Psr\SimpleCache\CacheInterface $repository
38
     * @param string $key
39
     * @param int|null $expire
40
     * @return void
41
     */
42
    public function __construct(CacheInterface $repository, $key = 'flysystem', $expire = null)
43
    {
44
        $this->key = $key;
45
        $this->expire = $expire;
46
        $this->repository = $repository;
47
    }
48
49
    /**
50
     * Load the cache.
51
     *
52
     * @return void
53
     */
54
    public function load()
55
    {
56
        $contents = $this->repository->get($this->key);
57
58
        if (!is_null($contents)) {
59
            $this->setFromStorage($contents);
60
        }
61
    }
62
63
    /**
64
     * Persist the cache.
65
     *
66
     * @return void
67
     */
68
    public function save()
69
    {
70
        $contents = $this->getForStorage();
71
72
        $this->repository->set($this->key, $contents, $this->expire);
73
    }
74
}