Passed
Push — development ( 2d33fb...38e0d5 )
by Alexander
02:48
created

CacheAdapterTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 32
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setAdapter() 0 4 1
A getAdapter() 0 8 2
1
<?php
2
/**
3
 * Trait for handling base adapter routines
4
 *
5
 * @file      CacheAdapterTrait.php
6
 *
7
 * PHP version 5.6+
8
 *
9
 * @author    Yancharuk Alexander <alex at itvault dot info>
10
 * @copyright © 2012-2018 Alexander Yancharuk <alex at itvault at info>
11
 * @date      2018-01-16 05:31
12
 * @license   The BSD 3-Clause License
13
 *            <https://tldrlegal.com/license/bsd-3-clause-license-(revised)>
14
 */
15
16
namespace Cache\Traits;
17
18
use Exception;
19
use Veles\Cache\Adapters\CacheAdapterAbstract;
20
use Veles\Cache\Adapters\CacheAdapterInterface;
21
22
trait CacheAdapterTrait
23
{
24
	/** @var CacheAdapterInterface */
25
	protected static $adapter;
26
	/** @var  string|CacheAdapterAbstract */
27
	protected static $adapter_name;
28
29
	/**
30
	 * Set cache adapter initialisation
31
	 *
32
	 * @param CacheAdapterInterface $adapter Adapter
33
	 */
34
	public static function setAdapter(CacheAdapterInterface $adapter)
35
	{
36
		self::$adapter = $adapter;
37
	}
38
39
	/**
40
	 * Get cache adapter instance
41
	 *
42
	 * @throws Exception
43
	 * @return CacheAdapterInterface
44
	 */
45
	public static function getAdapter()
46
	{
47
		if (null === self::$adapter) {
48
			throw new Exception('Adapter not set!');
49
		}
50
51
		return self::$adapter;
52
	}
53
}
54