SymfonyCacheFactory::createApcuAdapter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PublishingKit\Cache\Factories;
6
7
use Psr\Cache\CacheItemPoolInterface;
8
use PublishingKit\Cache\Contracts\Factories\CacheFactory;
9
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
10
use Symfony\Component\Cache\Adapter\ArrayAdapter;
11
use Symfony\Component\Cache\Adapter\ApcuAdapter;
12
use Symfony\Component\Cache\Adapter\MemcachedAdapter;
13
use Symfony\Component\Cache\Adapter\RedisAdapter;
14
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
15
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
16
17
final class SymfonyCacheFactory implements CacheFactory
18
{
19 24
    public function make(array $config): CacheItemPoolInterface
20
    {
21 24
        return $this->createAdapter($config);
22
    }
23
24 24
    private function createAdapter(array $config): CacheItemPoolInterface
25
    {
26 24
        if (!isset($config['driver'])) {
27 3
            $config['driver'] = 'filesystem';
28
        }
29 24
        switch ($config['driver']) {
30 24
            case 'array':
31 3
                $driver = $this->createArrayAdapter($config);
32 3
                break;
33 21
            case 'apcu':
34 3
                $driver = $this->createApcuAdapter($config);
35 3
                break;
36 18
            case 'memcached':
37 3
                $driver = $this->createMemcachedAdapter($config);
38 3
                break;
39 15
            case 'redis':
40 3
                $driver = $this->createRedisAdapter($config);
41 3
                break;
42 12
            case 'phpfiles':
43 3
                $driver = $this->createPhpFiles($config);
44 3
                break;
45 9
            case 'phparray':
46 3
                $driver = $this->createPhpArray($config);
47 3
                break;
48
            default:
49 9
                $driver = $this->createFilesystemAdapter($config);
50 9
                break;
51
        }
52 24
        return $driver;
53
    }
54
55 9
    private function createFilesystemAdapter(array $config): FilesystemAdapter
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

55
    private function createFilesystemAdapter(/** @scrutinizer ignore-unused */ array $config): FilesystemAdapter

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
    {
57 9
        return new FilesystemAdapter();
58
    }
59
60 3
    private function createArrayAdapter(array $config): ArrayAdapter
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

60
    private function createArrayAdapter(/** @scrutinizer ignore-unused */ array $config): ArrayAdapter

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
61
    {
62 3
        return new ArrayAdapter();
63
    }
64
65 3
    private function createApcuAdapter(array $config): ApcuAdapter
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

65
    private function createApcuAdapter(/** @scrutinizer ignore-unused */ array $config): ApcuAdapter

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
66
    {
67 3
        return new ApcuAdapter();
68
    }
69
70 3
    private function createMemcachedAdapter(array $config): MemcachedAdapter
71
    {
72 3
        $client = MemcachedAdapter::createConnection(
73 3
            $config['server']
74
        );
75 3
        return new MemcachedAdapter($client);
76
    }
77
78 3
    private function createRedisAdapter(array $config): RedisAdapter
79
    {
80 3
        $client = RedisAdapter::createConnection(
81 3
            $config['server']
82
        );
83 3
        return new RedisAdapter($client);
84
    }
85
86 3
    private function createPhpFiles(array $config): PhpFilesAdapter
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

86
    private function createPhpFiles(/** @scrutinizer ignore-unused */ array $config): PhpFilesAdapter

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
87
    {
88 3
        return new PhpFilesAdapter();
89
    }
90
91 3
    private function createPhpArray(array $config): PhpArrayAdapter
92
    {
93 3
        return new PhpArrayAdapter(
94 3
            $config['path'],
95 3
            $this->createAdapter($config['backup'])
96
        );
97
    }
98
}
99