CacheKey   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 76
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getBase() 0 3 1
A getId() 0 3 1
A getSub() 0 3 1
A setBase() 0 4 1
A setId() 0 4 1
A setSub() 0 4 1
A getHash() 0 3 1
A debug() 0 3 1
1
<?php
2
3
namespace Cachearium;
4
5
/**
6
 * Cache keys have three conceptual levels. This is useful for namespacing.
7
 *
8
 */
9
class CacheKey {
10
	/**
11
	 * This is the base key. It's the main index, so to speak. This is useful as a
12
	 * first level to separate cache data logically.
13
	 *
14
	 * @var string $base
15
	 */
16
	public $base;
17
18
	/**
19
	 * This is the second key, usually an id.
20
	 * @var string
21
	 */
22
	public $id;
23
24
	/**
25
	 *
26
	 * @var string
27
	 */
28
	public $sub;
29
30
	/**
31
	 * @param string $base Base string name for the type of cache (e.g., Event)
32
	 * @param string $id Item id
33
	 * @param string $sub If an item is cache in parts, this is used to specify the parts.
34
	 */
35
	public function __construct($base, $id, $sub = '') {
36
		$this->base = $base;
37
		$this->id = $id;
38
		$this->sub = $sub;
39
	}
40
41
	public function getBase() {
42
		return $this->base;
43
	}
44
45
	public function getId() {
46
		return $this->id;
47
	}
48
49
	public function getSub() {
50
		return $this->sub;
51
	}
52
53
	public function setBase($base) {
54
		$this->base = $base;
55
		return $this;
56
	}
57
58
	public function setId($id) {
59
		$this->id = $id;
60
		return $this;
61
	}
62
63
	public function setSub($sub) {
64
		$this->sub = $sub;
65
		return $this;
66
	}
67
68
	/**
69
	 * Returns a hash for key.
70
	 * @return string
71
	 */
72
	public function getHash() {
73
		return md5($this->base . $this->id . $this->sub);
74
	}
75
76
	/**
77
	 * Prints as a pretty string for debugging
78
	 * @return string
79
	 * @codeCoverageIgnore
80
	 */
81
	public function debug() {
82
		return $this->base . ", " . $this->id . ", " . print_r($this->sub, true);
83
	}
84
}
85