ExpiringKeyValue   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
set() 0 1 ?
get() 0 1 ?
delete() 0 1 ?
A pop() 0 7 2
A push() 0 3 1
1
<?php
2
3
namespace PhpConsole\Storage;
4
use PhpConsole\Storage;
5
6
/**
7
 * Abstract class for key-value stores with key auto-expire support
8
 *
9
 * @package PhpConsole
10
 * @version 3.1
11
 * @link http://consle.com
12
 * @author Sergey Barbushin http://linkedin.com/in/barbushin
13
 * @copyright © Sergey Barbushin, 2011-2013. All rights reserved.
14
 * @license http://www.opensource.org/licenses/BSD-3-Clause "The BSD 3-Clause License"
15
 * @codeCoverageIgnore
16
 */
17
abstract class ExpiringKeyValue extends Storage {
18
19
	/**
20
	 * Save data by auto-expire key
21
	 * @param $key
22
	 * @param string $data
23
	 * @param int $expire
24
	 */
25
	abstract protected function set($key, $data, $expire);
26
27
	/**
28
	 * Get data by key if not expired
29
	 * @param $key
30
	 * @return string
31
	 */
32
	abstract protected function get($key);
33
34
	/**
35
	 * Remove key in store
36
	 * @param $key
37
	 * @return mixed
38
	 */
39
	abstract protected function delete($key);
40
41
	/**
42
	 * Get postponed data from storage and delete
43
	 * @param string $key
44
	 * @return string
45
	 */
46
	public function pop($key) {
47
		$data = $this->get($key);
48
		if($data) {
49
			$this->delete($key);
50
		}
51
		return $data;
52
	}
53
54
	/**
55
	 * Save postponed data to storage
56
	 * @param string $key
57
	 * @param string $data
58
	 */
59
	public function push($key, $data) {
60
		$this->set($key, $data, $this->keyLifetime);
61
	}
62
}
63