Passed
Push — master ( 99e592...c06e17 )
by Jean-Christophe
05:25
created

SessionObject   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 40.74%

Importance

Changes 0
Metric Value
wmc 11
eloc 21
dl 0
loc 64
ccs 11
cts 27
cp 0.4074
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getTimeout() 0 5 2
A setDuration() 0 2 1
A getCreationTime() 0 2 1
A getDuration() 0 2 1
A setValue() 0 4 2
A __construct() 0 4 1
A isExpired() 0 2 1
A getValue() 0 4 2
1
<?php
2
3
namespace Ubiquity\utils\http\session;
4
5
class SessionObject {
6
	protected $value;
7
	protected $duration;
8
	protected $creationTime;
9
	
10 1
	public function __construct($value,$duration){
11 1
		$this->value=$value;
12 1
		$this->duration=$duration;
13 1
		$this->creationTime=time();
14 1
	}
15
	/**
16
	 * @return mixed
17
	 */
18 1
	public function getValue() {
19 1
		if(!$this->isExpired())
20 1
			return $this->value;
21 1
		return;
22
	}
23
24
	/**
25
	 * @return mixed
26
	 */
27
	public function getDuration() {
28
		return $this->duration;
29
	}
30
31
	/**
32
	 * @return mixed
33
	 */
34
	public function getCreationTime() {
35
		return $this->creationTime;
36
	}
37
38
	/**
39
	 * @param mixed $value
40
	 */
41
	public function setValue($value) {
42
		if($value!==$this->value)
43
			$this->creationTime=time();
44
		return $this->value = $value;
45
	}
46
47
	/**
48
	 * @param mixed $duration
49
	 */
50
	public function setDuration($duration) {
51
		$this->duration = $duration;
52
	}
53
	
54
	/**
55
	 * @return boolean
56
	 */
57 1
	public function isExpired(){
58 1
		return time()-$this->creationTime>$this->duration;
59
	}
60
	
61
	/**
62
	 * @return number
63
	 */
64
	public function getTimeout(){
65
		$timeout= $this->duration-(time()-$this->creationTime);
66
		if($timeout>0)
67
			return $timeout;
68
		return 0;
69
	}
70
71
}
72
73