HasCacheStoreTrait::createCacheAdapter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
use League\Flysystem\Cached\CachedAdapter;
0 ignored issues
show
Bug introduced by
The type League\Flysystem\Cached\CachedAdapter 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 League\Flysystem\Cached\Storage\Memory as MemoryStore;
0 ignored issues
show
Bug introduced by
The type League\Flysystem\Cached\Storage\Memory 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...
6
use Nip\Utility\Arr;
7
8
/**
9
 * Trait HasCacheStoreTrait
10
 * @package Nip\Filesystem\FilesystemManager
11
 */
12
trait HasCacheStoreTrait
13
{
14
    /**
15
     * @param $adapter
16
     * @param $config
17
     */
18
    protected function checkForCacheNeeded(&$adapter, &$config)
19
    {
20
        $cache = Arr::pull($config, 'cache');
21
        if (!empty($cache)) {
22
            $adapter = $this->createCacheAdapter($adapter, $cache);
23
        }
24
    }
25
26
    /**
27
     * @param $adapter
28
     * @param $cache
29
     * @return CachedAdapter
30
     */
31
    protected function createCacheAdapter($adapter, $cache)
32
    {
33
        return new CachedAdapter($adapter, $this->createCacheStore($cache));
34
    }
35
36
37
    /**
38
     * Create a cache store instance.
39
     *
40
     * @param mixed $config
41
     * @return \League\Flysystem\Cached\CacheInterface|MemoryStore|Cache
0 ignored issues
show
Bug introduced by
The type League\Flysystem\Cached\CacheInterface 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...
42
     *
43
     * @throws \InvalidArgumentException
44
     */
45
    protected function createCacheStore($config)
46
    {
47
        if ($config === true) {
48
            return new MemoryStore;
49
        }
50
51
        $cacheManager = $this->getCacheManager();
52
53
        return new Cache(
54
            $cacheManager->store($config['store']),
55
            $config['prefix'] ?? 'flysystem',
56
            $config['expire'] ?? null
57
        );
58
    }
59
60
    /**
61
     * @return mixed
62
     */
63
    protected function getCacheManager()
64
    {
65
        return app('cache');
66
    }
67
}
68