Test Failed
Pull Request — master (#46)
by Florian
02:40
created

CacheProvider::createNullCache()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 0
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;
13
use Symfony\Component\Cache\Simple\ArrayCache;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Cache\Simple\ArrayCache 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...
14
use Symfony\Component\Cache\Simple\ChainCache;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Cache\Simple\ChainCache 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...
15
use Symfony\Component\Cache\Simple\NullCache;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Cache\Simple\NullCache 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...
16
use Symfony\Component\Cache\Simple\PhpFilesCache;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Cache\Simple\PhpFilesCache 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
 * @codeCoverageIgnore
20
 */
21
final class CacheProvider
22
{
23
    /**
24
     * Create a "file cache", chained to a "memory cache" depending on symfony/cache version
25
     *
26
     * @param string $cacheDir
27
     * @return CacheInterface
28
     * @throws \Symfony\Component\Cache\Exception\CacheException
29
     */
30
    public static function createFileCache(string $cacheDir): CacheInterface
31
    {
32
        // >= Symfony 4.3
33
        if (class_exists('Symfony\Component\Cache\Psr16Cache')) {
34
            return new Psr16Cache(new ChainAdapter([
35
                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...
36
                new PhpFilesAdapter('', 0, $cacheDir),
37
            ]));
38
        }
39
40
        return new ChainCache([
41
            self::createMemoryCache(),
42
            new PhpFilesCache('', 0, $cacheDir)
43
        ]);
44
    }
45
46
    /**
47
     * Create a "memory cache" depending on symfony/cache version
48
     * @return CacheInterface
49
     */
50
    public static function createMemoryCache(): CacheInterface
51
    {
52
        // >= Symfony 4.3
53
        if (class_exists('Symfony\Component\Cache\Psr16Cache')) {
54
            return new Psr16Cache(new ArrayAdapter(0, false));
55
        }
56
57
        return new ArrayCache(0, false);
58
    }
59
60
    /**
61
     * Create a "null" cache (for annotations) depending on symfony/cache version
62
     *
63
     * @return CacheInterface
64
     */
65
    public static function createNullCache(): CacheInterface
66
    {
67
        // >= Symfony 4.3
68
        if (class_exists('Symfony\Component\Cache\Psr16Cache')) {
69
            return new Psr16Cache(new NullAdapter());
70
        }
71
72
        return new NullCache();
73
    }
74
}
75