CacheFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 14
dl 0
loc 38
rs 10
c 0
b 0
f 0
ccs 6
cts 6
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createCache() 0 7 2
A getValidCacheKey() 0 3 1
1
<?php
2
3
/*
4
 *
5
 * (c) Yaroslav Honcharuk <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Yarhon\RouteGuardBundle\Cache;
12
13
use Symfony\Component\Cache\Adapter\AdapterInterface;
14
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
15
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
16
17
/**
18
 * @author Yaroslav Honcharuk <[email protected]>
19
 */
20
class CacheFactory
21
{
22
    private static $keyEncodedChars = [
23
        '{' => '%7B',
24
        '}' => '%7D',
25
        '(' => '%28',
26
        ')' => '%29',
27
        '/' => '%2F',
28
        '\\' => '%5C',
29
        '@' => '%40',
30
        ':' => '%3A',
31
    ];
32
33
    /**
34
     * @param string $directory
35
     * @param string $namespace
36
     *
37
     * @return AdapterInterface
38
     */
39 21
    public static function createCache($directory, $namespace)
40
    {
41 21
        if (PhpFilesAdapter::isSupported()) {
42 20
            return new PhpFilesAdapter($namespace, 0, $directory);
43
        }
44
45 1
        return new FilesystemAdapter($namespace, 0, $directory);
46
    }
47
48
    /**
49
     * @see \Symfony\Component\Cache\CacheItem::validateKey
50
     *
51
     * @param string $key
52
     *
53
     * @return string
54
     */
55 37
    public static function getValidCacheKey($key)
56
    {
57 37
        return strtr($key, static::$keyEncodedChars);
0 ignored issues
show
Bug introduced by
Since $keyEncodedChars is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $keyEncodedChars to at least protected.
Loading history...
58
    }
59
}
60