Cache   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 20
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A write() 0 4 1
A load() 0 7 3
1
<?php
2
/* @description     Transformation Style Sheets - Revolutionising PHP templating    *
3
 * @author          Tom Butler [email protected]                                             *
4
 * @copyright       2017 Tom Butler <[email protected]> | https://r.je/                      *
5
 * @license         http://www.opensource.org/licenses/bsd-license.php  BSD License *
6
 * @version         1.2                                                             */
7
namespace Transphporm;
8
class Cache {
9
	private $cache;
10
11
	public function __construct(\ArrayAccess $cache) {
12
		$this->cache = $cache;
13
	}
14
15
	public function write($key, $content) {
16
		$this->cache[md5($key)] = ['content' => $content, 'timestamp' => time()];
17
		return $content;
18
	}
19
20
	public function load($key, $modified = 0) {
21
		$key = md5($key);
22
		if (isset($this->cache[$key]) && $this->cache[$key]['timestamp'] >= $modified) {
23
			return $this->cache[$key]['content'];
24
		}
25
		else return false;
26
	}
27
}