Completed
Pull Request — master (#46)
by Florian
04:11
created

CacheProvider::createFileCache()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 13
ccs 0
cts 8
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tebru\Gson\Internal;
6
7
use Psr\SimpleCache\CacheInterface;
8
use Symfony\Component\Cache\Adapter\ArrayAdapter;
9
use Symfony\Component\Cache\Adapter\ChainAdapter;
10
use Symfony\Component\Cache\Adapter\NullAdapter;
11
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
12
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...
13
use Symfony\Component\Cache\Simple\ArrayCache;
14
use Symfony\Component\Cache\Simple\ChainCache;
15
use Symfony\Component\Cache\Simple\NullCache;
16
use Symfony\Component\Cache\Simple\PhpFilesCache;
17
18
final class CacheProvider
19
{
20
    public static function createFileCache(string $cacheDir): CacheInterface
21
    {
22
        // >= Symfony 4.3
23
        if (class_exists('Symfony\Component\Cache\Psr16Cache')) {
24
            return new Psr16Cache(new ChainAdapter([
25
                new Psr16Adapter(self::createMemoryCache()),
0 ignored issues
show
Bug introduced by
The type Tebru\Gson\Internal\Psr16Adapter 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...
26
                new PhpFilesAdapter('', 0, $cacheDir),
27
            ]));
28
        }
29
30
        return new ChainCache([
31
            self::createMemoryCache(),
32
            new PhpFilesCache('', 0, $cacheDir)
33
        ]);
34
    }
35
36
    /**
37
     * Create a "memory cache" depending on symfony/cache version
38
     * @return CacheInterface
39
     */
40 3
    public static function createMemoryCache(): CacheInterface
41
    {
42
        // >= Symfony 4.3
43 3
        if (class_exists('Symfony\Component\Cache\Psr16Cache')) {
44
            return new Psr16Cache(new ArrayAdapter(0, false));
45
        }
46
47 3
        return new ArrayCache(0, false);
48
    }
49
50
    /**
51
     * Create a "null" cache (for annotations) depending on symfony/cache version
52
     *
53
     * @return CacheInterface
54
     */
55 3
    public static function createNullCache(): CacheInterface
56
    {
57
        // >= Symfony 4.3
58 3
        if (class_exists('Symfony\Component\Cache\Psr16Cache')) {
59
            return new Psr16Cache(new NullAdapter());
60
        }
61
62 3
        return new NullCache();
63
    }
64
}
65