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

HasCacheStoreTrait::checkForCacheNeeded()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
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