Session   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 5
A getKeysData() 0 3 2
A saveKeysData() 0 3 1
1
<?php
2
3
namespace PhpConsole\Storage;
4
5
/**
6
 * $_SESSION storage for postponed response data. Is used by default.
7
 *
8
 * @package PhpConsole
9
 * @version 3.1
10
 * @link http://consle.com
11
 * @author Sergey Barbushin http://linkedin.com/in/barbushin
12
 * @copyright © Sergey Barbushin, 2011-2013. All rights reserved.
13
 * @license http://www.opensource.org/licenses/BSD-3-Clause "The BSD 3-Clause License"
14
 */
15
class Session extends AllKeysList {
16
17
	protected $sessionKey;
18
19
	/**
20
	 * @param string $sessionKey Key name in $_SESSION variable
21
	 * @param bool $autoStart Start session if it's not started
22
	 */
23 3
	public function __construct($sessionKey = '__PHP_Console_postponed', $autoStart = true) {
24 3
        	if($autoStart && (defined('PHP_SESSION_ACTIVE') ? session_status() != PHP_SESSION_ACTIVE : !session_id()) && !headers_sent()) {
25
        		session_start();
26
		}
27 3
		register_shutdown_function('session_write_close'); // force saving session data if session handler is overridden
28 3
		$this->sessionKey = $sessionKey;
29 3
	}
30
31 3
	protected function getKeysData() {
32 3
		return isset($_SESSION[$this->sessionKey]) ? $_SESSION[$this->sessionKey] : array();
33
	}
34
35 3
	protected function saveKeysData(array $keysData) {
36 3
		$_SESSION[$this->sessionKey] = $keysData;
37 3
	}
38
}
39