Cache   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 51
ccs 10
cts 10
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A has() 0 4 1
A read() 0 4 2
A write() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of Symnedi.
5
 * Copyright (c) 2014 Tomas Votruba (http://tomasvotruba.cz)
6
 */
7
8
namespace Symnedi\Validator\Caching;
9
10
use Nette\Caching\Cache AS NetteCache;
11
use Nette\Caching\IStorage;
12
use Symfony\Component\Validator\Mapping\Cache\CacheInterface;
13
use Symfony\Component\Validator\Mapping\ClassMetadata;
14
15
16
final class Cache implements CacheInterface
17
{
18
19
	/**
20
	 * @var string
21
	 */
22
	const CACHE_NAMESPACE = 'Symfony.Validator';
23
24
	/**
25
	 * @var NetteCache
26
	 */
27
	private $cache;
28
29
30
	/**
31
	 * @param IStorage $storage
32
	 * @param string $namespace
33
	 */
34 2
	public function __construct(IStorage $storage, $namespace = self::CACHE_NAMESPACE)
35
	{
36 2
		$this->cache = new NetteCache($storage, $namespace);
37 2
	}
38
39
40
	/**
41
	 * {@inheritdoc}
42
	 */
43 1
	public function has($class)
44
	{
45 1
		return $this->cache->load($class) !== NULL;
46
	}
47
48
49
	/**
50
	 * {@inheritdoc}
51
	 */
52 1
	public function read($class)
53
	{
54 1
		return $this->has($class) ? $this->cache->load($class) : FALSE;
55
	}
56
57
58
	/**
59
	 * {@inheritdoc}
60
	 */
61 1
	public function write(ClassMetadata $metadata)
62
	{
63 1
		$this->cache->save($metadata->getClassName(), $metadata);
64 1
	}
65
66
}
67