InteractsWithCache::getCache()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 5
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 11
rs 9.6111
1
<?php
2
3
/*
4
 * This file is part of the mingyoung/dingtalk.
5
 *
6
 * (c) 张铭阳 <[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 EasyDingTalk\Kernel\Concerns;
13
14
use Psr\SimpleCache\CacheInterface;
15
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
16
use Symfony\Component\Cache\Psr16Cache;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Cache\Psr16Cache 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
use Symfony\Component\Cache\Simple\FilesystemCache;
18
19
trait InteractsWithCache
20
{
21
    /**
22
     * @var \Psr\SimpleCache\CacheInterface
23
     */
24
    protected $cache;
25
26
    /**
27
     * @return \Psr\SimpleCache\CacheInterface
28
     */
29
    public function getCache()
30
    {
31
        if ($this->cache) {
32
            return $this->cache;
33
        }
34
35
        if (property_exists($this, 'app') && $this->app->offsetExists('cache') && ($this->app['cache'] instanceof CacheInterface)) {
36
            return $this->cache = $this->app['cache'];
37
        }
38
39
        return $this->cache = $this->createDefaultCache();
40
    }
41
42
    /**
43
     * @return \Psr\SimpleCache\CacheInterface
44
     */
45
    protected function createDefaultCache()
46
    {
47
        if (class_exists(Psr16Cache::class)) {
48
            return new Psr16Cache(new FilesystemAdapter('easydingtalk'));
49
        }
50
51
        return new FilesystemCache('easydingtalk');
52
    }
53
}
54