Issues (19)

src/Cache/DoctrineCacheAdapter.php (1 issue)

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