Test Setup Failed
Push — master ( dee4cd...d18a68 )
by Gabriel
06:19 queued 12s
created

HasCacheStoreTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 46
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A checkForCacheNeeded() 0 7 2
A createCacheAdapter() 0 4 1
A createCacheStore() 0 12 1
1
<?php
2
3
namespace Nip\Filesystem\FilesystemManager;
4
5
use League\Flysystem\Cached\CachedAdapter;
6
use League\Flysystem\Cached\Storage\Memory as MemoryStore;
7
use Nip\Utility\Arr;
8
9
/**
10
 * Trait HasCacheStoreTrait
11
 * @package Nip\Filesystem\FilesystemManager
12
 */
13
trait HasCacheStoreTrait
14
{
15
    /**
16
     * @param $adapter
17
     * @param $config
18
     */
19 2
    protected function checkForCacheNeeded(&$adapter, &$config)
20
    {
21 2
        $cache = Arr::pull($config, 'cache');
22 2
        if (!empty($cache)) {
23 1
            $adapter = $this->createCacheAdapter($adapter, $cache);
24
        }
25 2
    }
26
27
    /**
28
     * @param $adapter
29
     * @param $cache
30
     * @return CachedAdapter
31
     */
32 1
    protected function createCacheAdapter($adapter, $cache)
33
    {
34 1
        return new CachedAdapter($adapter, $this->createCacheStore($cache));
35
    }
36
37
38
    /**
39
     * Create a cache store instance.
40
     *
41
     * @param mixed $config
42
     * @return \League\Flysystem\Cached\CacheInterface|MemoryStore
43
     *
44
     * @throws \InvalidArgumentException
45
     */
46 1
    protected function createCacheStore($config)
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
    {
48
//        if ($config === true) {
49 1
        return new MemoryStore;
50
//        }
51
//
52
//        return new Cache(
53
//            $this->app['cache']->store($config['store']),
54
//            $config['prefix'] ?? 'flysystem',
55
//            $config['expire'] ?? null
56
//        );
57
    }
58
}
59