Session   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 35.29%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 0
dl 0
loc 62
ccs 6
cts 17
cp 0.3529
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 5 1
A destroy() 0 4 1
A put() 0 4 1
A get() 0 8 2
1
<?php
2
3
/**
4
 * This file is part of the PHP Generics package.
5
 *
6
 * @package Generics
7
 */
8
namespace Generics\Client;
9
10
/**
11
 * This class provides session provider
12
 *
13
 * @author Maik Greubel <[email protected]>
14
 *
15
 */
16
class Session
17
{
18
19
    private $sessionId;
20
21
    /**
22
     * Session variable container
23
     * @var array
24
     */
25
    private $sessionContainer;
26
27
    /**
28
     * Create a new session provider
29
     */
30 1
    public function __construct(array &$container)
31
    {
32 1
        $this->sessionContainer = &$container;
33 1
    }
34
35
    /**
36
     * Create session
37
     */
38
    public function create()
39
    {
40
        session_start();
41
        $this->sessionId = session_id();
42
    }
43
44
    /**
45
     * Destroy session
46
     */
47
    public function destroy()
48
    {
49
        session_destroy();
50
    }
51
52
    /**
53
     * Add a new identifier with corresponding value to session storage
54
     *
55
     * @param string $key
56
     * @param string $value
57
     */
58 1
    public function put($key, $value)
59
    {
60 1
        $this->sessionContainer[$key] = $value;
61 1
    }
62
63
    /**
64
     * Retrieve value from session storage for corresponding key
65
     *
66
     * @param string $key
67
     * @return NULL|string
68
     */
69
    public function get($key)
70
    {
71
        if (! isset($this->sessionContainer[$key])) {
72
            return null;
73
        }
74
75
        return $this->sessionContainer[$key];
76
    }
77
}
78