Completed
Push — master ( 40d0c0...3b4436 )
by Matthew
03:01
created

SymfonyCacheFactory::make()   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 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
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
13
final class SymfonyCacheFactory implements CacheFactory
14
{
15 12
    public function make(array $config): CacheItemPoolInterface
16
    {
17 12
        return $this->createAdapter($config);
18
    }
19
20 12
    private function createAdapter(array $config): CacheItemPoolInterface
21
    {
22 12
        if (!isset($config['driver'])) {
23 3
            $config['driver'] = 'filesystem';
24
        }
25 12
        switch ($config['driver']) {
26 12
            case 'array':
27 3
                $driver = $this->createArrayAdapter($config);
28 3
                break;
29 9
            case 'apcu':
30 3
                $driver = $this->createApcuAdapter($config);
31 3
                break;
32
            default:
33 6
                $driver = $this->createFilesystemAdapter($config);
34 6
                break;
35
        }
36 12
        return $driver;
37
    }
38
39 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

39
    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...
40
    {
41 6
        return new FilesystemAdapter();
42
    }
43
44 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

44
    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...
45
    {
46 3
        return new ArrayAdapter();
47
    }
48
49 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

49
    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...
50
    {
51 3
        return new ApcuAdapter();
52
    }
53
}
54