DoctrineCacheAdapter   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 41
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A put() 0 3 1
A evict() 0 3 1
A load() 0 5 2
A clear() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Metadata\Cache;
6
7
use Doctrine\Common\Cache\Cache;
8
use Metadata\ClassMetadata;
9
10
/**
11
 * @author Henrik Bjornskov <[email protected]>
12
 */
13
class DoctrineCacheAdapter implements CacheInterface, ClearableCacheInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    private $prefix;
19
    /**
20
     * @var Cache
21
     */
22
    private $cache;
23
24 2
    public function __construct(string $prefix, Cache $cache)
25
    {
26 2
        $this->prefix = $prefix;
27 2
        $this->cache = $cache;
28 2
    }
29
30 2
    public function load(string $class): ?ClassMetadata
31
    {
32 2
        $cache = $this->cache->fetch($this->prefix . $class);
33
34 2
        return false === $cache ? null : $cache;
35
    }
36
37 2
    public function put(ClassMetadata $metadata): void
38
    {
39 2
        $this->cache->save($this->prefix . $metadata->name, $metadata);
40 2
    }
41
42 2
    public function evict(string $class): void
43
    {
44 2
        $this->cache->delete($this->prefix . $class);
45 2
    }
46
47
    public function clear(): bool
48
    {
49
        if (method_exists($this->cache, 'deleteAll')) { // or $this->cache instanceof ClearableCache
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
50
            return call_user_func([$this->cache, 'deleteAll']);
51
        }
52
53
        return false;
54
    }
55
}
56