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

SessionObject::setDuration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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