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

CacheAdapterTrait::setAdapter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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