Test Failed
Push — master ( 2ebd79...2dee01 )
by Jean-Christophe
01:41 queued 13s
created

PhpSession   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 14
eloc 21
c 1
b 0
f 1
dl 0
loc 49
ccs 25
cts 30
cp 0.8333
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A delete() 0 2 1
A terminate() 0 11 3
A start() 0 9 5
A set() 0 2 1
A get() 0 2 1
A exists() 0 2 1
A isStarted() 0 2 1
A getAll() 0 2 1
1
<?php
2
3
namespace Ubiquity\utils\http\session;
4
5
/**
6
 * Default php session.
7
 * Ubiquity\utils\http\session$PhpSession
8
 * This class is part of Ubiquity
9
 *
10
 * @author jcheron <[email protected]>
11
 * @version 1.0.0
12
 *
13
 */
14
class PhpSession extends AbstractSession {
15
16 13
	public function set($key, $value) {
17 13
		return $_SESSION [$key] = $value;
18
	}
19
20 11
	public function get($key, $default = null) {
21 11
		return $_SESSION [$key] ?? $default;
22
	}
23
24 59
	public function start($name = null) {
25 59
		if (! $this->isStarted ()) {
26 36
			if (isset ( $name ) && $name !== '') {
27
				$this->name = $name;
28
			}
29 36
			if (isset ( $this->name )) {
30
				\session_name ( $this->name );
31
			}
32 36
			\session_start ();
33
		}
34 59
	}
35
36 2
	public function terminate() {
37 2
		if (! $this->isStarted ())
38
			return;
39 2
		$this->start ();
40 2
		$_SESSION = array ();
41
42 2
		if (\ini_get ( 'session.use_cookies' )) {
43 2
			$params = \session_get_cookie_params ();
44 2
			\setcookie ( \session_name (), '', \time () - 42000, $params ['path'], $params ['domain'], $params ['secure'], $params ['httponly'] );
45
		}
46 2
		\session_destroy ();
47 2
	}
48
49 59
	public function isStarted() {
50 59
		return \session_status () == PHP_SESSION_ACTIVE;
51
	}
52
53 19
	public function exists($key) {
54 19
		return isset ( $_SESSION [$key] );
55
	}
56
57
	public function getAll() {
58
		return $_SESSION;
59
	}
60
61 3
	public function delete($key) {
62 3
		unset ( $_SESSION [$key] );
63 3
	}
64
}
65
66