Completed
Pull Request — master (#14)
by Pavel
04:14
created

VoidEntityCache   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 89.47%

Importance

Changes 0
Metric Value
dl 0
loc 54
c 0
b 0
f 0
wmc 7
lcom 1
cbo 4
ccs 17
cts 19
cp 0.8947
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A get() 0 6 1
A set() 0 4 1
A getConfiguration() 0 4 1
A getMetadata() 0 4 1
A logSkip() 0 6 1
1
<?php
2
3
namespace Bankiru\Api\Doctrine\Cache;
4
5
use Bankiru\Api\Doctrine\EntityDataCacheInterface;
6
use Bankiru\Api\Doctrine\Mapping\ApiMetadata;
7
use Psr\Log\LoggerInterface;
8
use Psr\Log\NullLogger;
9
10
final class VoidEntityCache implements EntityDataCacheInterface
11
{
12
    /** @var  ApiMetadata */
13
    private $metadata;
14
    /**
15
     * @var LoggerInterface
16
     */
17
    private $logger;
18
19
    /**
20
     * VoidEntityCache constructor.
21
     *
22
     * @param ApiMetadata     $metadata
23
     * @param LoggerInterface $logger
24
     */
25 19
    public function __construct(ApiMetadata $metadata, LoggerInterface $logger = null)
26
    {
27 19
        $this->metadata = $metadata;
28 19
        $this->logger   = $logger ?: new NullLogger();
29 19
    }
30
31
    /** {@inheritdoc} */
32 10
    public function get(array $identifier)
33
    {
34 10
        $this->logSkip();
35
36 10
        return null;
37
    }
38
39
    /** {@inheritdoc} */
40 10
    public function set(array $identifier, $data)
41
    {
42 10
        $this->logSkip();
43 10
    }
44
45
    /** {@inheritdoc} */
46
    public function getConfiguration()
47
    {
48
        return CacheConfiguration::disabled();
49
    }
50
51
    /** {@inheritdoc} */
52 10
    public function getMetadata()
53
    {
54 10
        return $this->metadata;
55
    }
56
57 10
    private function logSkip()
58
    {
59 10
        $this->logger->debug(
60 10
            sprintf('Skipping entity cache for %s: not configured', $this->getMetadata()->getName())
61 10
        );
62 10
    }
63
}
64