Completed
Branch master (1afb45)
by Timothy
04:13
created

NullDriver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Ion
4
 *
5
 * Building blocks for web development
6
 *
7
 * @package	 Ion
8
 * @author	  Timothy J. Warren
9
 * @copyright   Copyright (c) 2015 - 2016
10
 * @license	 MIT
11
 */
12
13
namespace Aviat\Ion\Cache\Driver;
14
15
use Aviat\Ion\Di\ContainerInterface;
16
17
/**
18
 * The Driver for no real cache
19
 */
20
class NullDriver implements \Aviat\Ion\Cache\CacheDriverInterface {
21
22
	/**
23
	 * 'Cache' for Null data store
24
	 */
25
	protected $data;
26
27
	/**
28
	 * Create the Redis cache driver
29
	 */
30
	public function __construct(ContainerInterface $container)
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
	{
32
		$this->data = [];
33
	}
34
35
	/**
36
	 * Retreive a value from the cache backend
37
	 *
38
	 * @param string $key
39
	 * @return mixed
40
	 */
41
	public function get($key)
42
	{
43
		return (array_key_exists($key, $this->data))
44
			? $this->data[$key]
45
			: NULL;
46
	}
47
48
	/**
49
	 * Set a cached value
50
	 *
51
	 * @param string $key
52
	 * @param mixed $value
53
	 * @return CacheDriverInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be NullDriver?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
54
	 */
55
	public function set($key, $value)
56
	{
57
		$this->data[$key] = $value;
58
		return $this;
59
	}
60
61
	/**
62
	 * Invalidate a cached value
63
	 *
64
	 * @param string $key
65
	 * @return CacheDriverInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be NullDriver?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
66
	 */
67
	public function invalidate($key)
68
	{
69
		unset($this->data[$key]);
70
		return $this;
71
	}
72
73
	/**
74
	 * Clear the contents of the cache
75
	 *
76
	 * @return void
77
	 */
78
	public function invalidateAll()
79
	{
80
		$this->data = [];
81
	}
82
}
83
// End of NullDriver.php