Session   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 0
dl 0
loc 92
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A set() 0 5 1
A get() 0 5 2
A start() 0 4 2
A setFlashBag() 0 7 2
A destroy() 0 18 2
1
<?php
2
3
/**
4
 * Manage Sessions
5
 *
6
 * @category  	lib
7
 * @author    	Judicaël Paquet <[email protected]>
8
 * @copyright 	Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93)
9
 * @license   	https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël
10
 * @version   	Release: 1.0.0
11
 * @filesource	https://github.com/las93/venus2
12
 * @link      	https://github.com/las93
13
 * @since     	1.0
14
 */
15
namespace Venus\lib;
16
17
/**
18
 * This class manage the Sessions
19
 *
20
 * @category  	lib
21
 * @author    	Judicaël Paquet <[email protected]>
22
 * @copyright 	Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93)
23
 * @license   	https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël
24
 * @version   	Release: 1.0.0
25
 * @filesource	https://github.com/las93/venus2
26
 * @link      	https://github.com/las93
27
 * @since     	1.0
28
 */
29
class Session
30
{	
0 ignored issues
show
Coding Style introduced by
The opening class brace should be on a newline by itself.
Loading history...
31
	/**
32
	 * constructor
33
	 *
34
	 * @access public
35
	 * @return \Venus\lib\Session
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
36
	 */
37
	public function __construct()
38
	{	
39
		$this->start();
40
	}
41
	
42
  	/**
43
  	 * set a value
44
  	 *
45
  	 * @access public
46
  	 * @param  string $sName name of the session
47
  	 * @param  mixed $mValue value of this sesion var
48
  	 * @return Session
49
  	 */
50
  	public function set(string $sName, $mValue) : Session
51
	{
52
    	$_SESSION[$sName] = $mValue;
53
    	return $this;
54
  	}
55
56
  	/**
57
  	 * set a value
58
  	 *
59
  	 * @access public
60
  	 * @param  string $sName name of the session
61
  	 * @return mixed
62
  	 */
63
  	public function get(string $sName)
64
	{
65
  		if (isset($_SESSION[$sName])) { return $_SESSION[$sName]; }
66
  		else { return false; }
67
  	}
68
69
  	/**
70
  	 * start the session
71
  	 *
72
  	 * @access public
73
  	 * @return mixed
74
  	 */
75
  	public function start()
76
	{
77
		if (!session_id()) { session_start(); }
78
  	}
79
80
  	/**
81
  	 * set a flashbag value
82
  	 *
83
  	 * @access public
84
  	 * @param  string $sName name of the session
85
  	 * @param  string $sValue value of this sesion var
86
  	 * @return \Venus\lib\Session
87
	 */
88
 	 public function setFlashBag($sName, $sValue)
89
	 {
90
  		if (!isset($_SESSION['flashbag'])) { $_SESSION['flashbag'] = array(); }
91
92
  		$_SESSION['flashbag'][$sName] = $sValue;
93
  		return $this;
94
	}
95
	
96
	/**
97
	 * destroy the session
98
	 *
99
	 * @access public
100
	 * @return mixed
101
	 */
102
	public function destroy()
103
	{
104
		session_start();
105
106
		$_SESSION = array();
107
		
108
		if (ini_get("session.use_cookies")) {
109
		    
110
			$aParams = session_get_cookie_params();
111
		    
112
		    setcookie(session_name(), '', time() - 42000,
113
		        $aParams["path"], $aParams["domain"],
114
		        $aParams["secure"], $aParams["httponly"]
115
		    );
116
		}
117
118
		session_destroy();
119
	}
120
}
121