CacheLogEnum::getNames()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace Cachearium;
4
5
/**
6
 * Enum Class for cache logs
7
 *
8
 * @author corollarium
9
 *
10
 */
11
class CacheLogEnum {
12
	const ACCESSED = 'accessed';
13
	const MISSED = 'missed';
14
	const DELETED = 'deleted';
15
	const CLEANED = 'cleaned';
16
	const SAVED = 'saved';
17
	const PREFETCHED = 'prefetched';
18
19
	public static function getNames() {
20
		return array(
21
			self::ACCESSED   => '<span class="cache-success">Accessed</span>',
22
			self::MISSED     => '<span class="cache-miss">Missed</span>',
23
			self::DELETED    => '<span class="cache-deleted">Deleted</span>',
24
			self::CLEANED    => '<span class="cache-cleaned">Cleaned</span>',
25
			self::SAVED      => '<span class="cache-save">Saved</span>',
26
			self::PREFETCHED => '<span class="cache-prefetched">Prefetched</span>'
27
		);
28
	}
29
30
	/**
31
	 * Returns an array with all enum values.
32
	 * @return array
33
	 * @codeCoverageIgnore
34
	 */
35
	static public function getAll() {
36
		return array_keys(static::getNames());
37
	}
38
39
	/**
40
	 * Checks if a value is a valid grant
41
	 *
42
	 * @param string $value
43
	 * @return boolean true if valid
44
	 * @codeCoverageIgnore
45
	 */
46
	static public function valid($value) {
47
		return array_key_exists($value, static::getNames());
48
	}
49
50
	/**
51
	 * Given a name, returns its value or a string saying it is invalid.
52
	 *
53
	 * @param string $value
54
	 * @return string
55
	 * @codeCoverageIgnore
56
	 */
57
	static public function getName($value) {
58
		if (static::valid($value)) {
59
			$x = static::getNames();
60
			return $x[$value];
61
		}
62
		return 'Invalid: ' . htmlspecialchars($value);
63
	}
64
}
65