InteractsWithCache::getCache()   B
last analyzed

Complexity

Conditions 6
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
eloc 6
nc 3
nop 0
dl 0
loc 12
ccs 0
cts 10
cp 0
crap 42
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the docodeit/wechat.
5
 *
6
 * (c) docodeit <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace JinWeChat\Kernel\Traits;
13
14
use JinWeChat\Kernel\ServiceContainer;
15
use Psr\SimpleCache\CacheInterface;
16
use Symfony\Component\Cache\Simple\FilesystemCache;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Cache\Simple\FilesystemCache 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...
17
18
/**
19
 * Trait InteractsWithCache.
20
 *
21
 * @author docodeit <[email protected]>
22
 */
23
trait InteractsWithCache
24
{
25
    /**
26
     * @var \Psr\SimpleCache\CacheInterface
27
     */
28
    protected $cache;
29
30
    /**
31
     * Get cache instance.
32
     *
33
     * @return \Psr\SimpleCache\CacheInterface
34
     */
35
    public function getCache()
36
    {
37
        if ($this->cache) {
38
            return $this->cache;
39
        }
40
41
        if (property_exists($this, 'app') && $this->app instanceof ServiceContainer
42
            && isset($this->app['cache']) && $this->app['cache'] instanceof CacheInterface) {
43
            return $this->cache = $this->app['cache'];
44
        }
45
46
        return $this->cache = $this->createDefaultCache();
47
    }
48
49
    /**
50
     * Set cache instance.
51
     *
52
     * @param \Psr\SimpleCache\CacheInterface $cache
53
     *
54
     * @return $this
55
     */
56
    public function setCache(CacheInterface $cache)
57
    {
58
        $this->cache = $cache;
59
60
        return $this;
61
    }
62
63
    /**
64
     * @return \Symfony\Component\Cache\Simple\FilesystemCache
65
     */
66
    protected function createDefaultCache()
67
    {
68
        return new FilesystemCache();
69
    }
70
}
71