Completed
Push — development ( 8d5bb4...361c30 )
by Alexander
02:45
created

CacheAdapterTrait::getAdapter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 6
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 Veles\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 2
	public static function setAdapter(CacheAdapterInterface $adapter)
35
	{
36 2
		self::$adapter = $adapter;
37 2
	}
38
39
	/**
40
	 * Get cache adapter instance
41
	 *
42
	 * @throws Exception
43
	 * @return CacheAdapterInterface
44
	 */
45 6
	public static function getAdapter()
46
	{
47 6
		if (null === self::$adapter) {
48 2
			throw new Exception('Adapter not set!');
49
		}
50
51 4
		return self::$adapter;
52
	}
53
}
54