Completed
Push — master ( 567fe0...b83b55 )
by Matthew
02:28
created

SymfonyCacheFactory::createPhpFiles()   A

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
16
final class SymfonyCacheFactory implements CacheFactory
17
{
18 18
    public function make(array $config): CacheItemPoolInterface
19
    {
20 18
        return $this->createAdapter($config);
21
    }
22
23 18
    private function createAdapter(array $config): CacheItemPoolInterface
24
    {
25 18
        if (!isset($config['driver'])) {
26 3
            $config['driver'] = 'filesystem';
27
        }
28 18
        switch ($config['driver']) {
29 18
            case 'array':
30 3
                $driver = $this->createArrayAdapter($config);
31 3
                break;
32 15
            case 'apcu':
33 3
                $driver = $this->createApcuAdapter($config);
34 3
                break;
35 12
            case 'memcached':
36
                $driver = $this->createMemcachedAdapter($config);
37
                break;
38 12
            case 'redis':
39 3
                $driver = $this->createRedisAdapter($config);
40 3
                break;
41 9
            case 'phpfiles':
42 3
                $driver = $this->createPhpFiles($config);
43 3
                break;
44
            default:
45 6
                $driver = $this->createFilesystemAdapter($config);
46 6
                break;
47
        }
48 18
        return $driver;
49
    }
50
51 6
    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

51
    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...
52
    {
53 6
        return new FilesystemAdapter();
54
    }
55
56 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

56
    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...
57
    {
58 3
        return new ArrayAdapter();
59
    }
60
61 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

61
    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...
62
    {
63 3
        return new ApcuAdapter();
64
    }
65
66
    private function createMemcachedAdapter(array $config): MemcachedAdapter
67
    {
68
        $client = MemcachedAdapter::createConnection(
69
            $config['servers']
70
        );
71
        return new MemcachedAdapter($client);
72
    }
73
74 3
    private function createRedisAdapter(array $config): RedisAdapter
75
    {
76 3
        $client = RedisAdapter::createConnection(
77 3
            $config['server']
78
        );
79 3
        return new RedisAdapter($client);
80
    }
81
82 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

82
    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...
83
    {
84 3
        return new PhpFilesAdapter();
85
    }
86
}
87