Cache::read()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 2
eloc 2
nc 2
nop 1
crap 2
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