Passed
Pull Request — master (#46)
by Florian
02:17
created

CacheProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 14
c 1
b 0
f 0
dl 0
loc 45
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createMemoryCache() 0 8 2
A createNullCache() 0 8 2
A createFileCache() 0 13 2
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
/**
19
 * @codeCoverageIgnore
20
 */
21
final class CacheProvider
22
{
23
    public static function createFileCache(string $cacheDir): CacheInterface
24
    {
25
        // >= Symfony 4.3
26
        if (class_exists('Symfony\Component\Cache\Psr16Cache')) {
27
            return new Psr16Cache(new ChainAdapter([
28
                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...
29
                new PhpFilesAdapter('', 0, $cacheDir),
30
            ]));
31
        }
32
33
        return new ChainCache([
34
            self::createMemoryCache(),
35
            new PhpFilesCache('', 0, $cacheDir)
36
        ]);
37
    }
38
39
    /**
40
     * Create a "memory cache" depending on symfony/cache version
41
     * @return CacheInterface
42
     */
43
    public static function createMemoryCache(): CacheInterface
44
    {
45
        // >= Symfony 4.3
46
        if (class_exists('Symfony\Component\Cache\Psr16Cache')) {
47
            return new Psr16Cache(new ArrayAdapter(0, false));
48
        }
49
50
        return new ArrayCache(0, false);
51
    }
52
53
    /**
54
     * Create a "null" cache (for annotations) depending on symfony/cache version
55
     *
56
     * @return CacheInterface
57
     */
58
    public static function createNullCache(): CacheInterface
59
    {
60
        // >= Symfony 4.3
61
        if (class_exists('Symfony\Component\Cache\Psr16Cache')) {
62
            return new Psr16Cache(new NullAdapter());
63
        }
64
65
        return new NullCache();
66
    }
67
}
68