Passed
Push — master ( 0602c9...8f96ba )
by Thierry
02:02
created

Manager   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 10
dl 0
loc 107
rs 10
c 1
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 2
A newId() 0 3 1
A getId() 0 3 1
A all() 0 3 1
A has() 0 3 1
A delete() 0 5 2
A set() 0 3 1
A clear() 0 3 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon\Session;
4
5
use Jaxon\Contracts\Session as SessionContract;
6
7
class Manager implements SessionContract
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class Manager
Loading history...
8
{
9
    /**
10
     * Get the current session id
11
     *
12
     * @return string           The session id
13
     */
14
    public function getId()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
15
    {
16
        return session_id();
17
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
18
19
    /**
20
     * Generate a new session id
21
     *
22
     * @param bool          $bDeleteData         Whether to delete data from the previous session
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 10 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 9 found
Loading history...
23
     *
24
     * @return void
25
     */
26
    public function newId($bDeleteData = false)
27
    {
28
        session_regenerate_id($bDeleteData);
29
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
30
31
    /**
32
     * Save data in the session
33
     *
34
     * @param string        $sKey                The session key
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter name; 16 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
35
     * @param string        $xValue              The session value
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 14 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
36
     *
37
     * @return void
38
     */
39
    public function set($sKey, $xValue)
40
    {
41
        $_SESSION[$sKey] = $xValue;
42
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
43
44
    /**
45
     * Save data in the session, that will be available only until the next call
46
     *
47
     * @param string        $sKey                The session key
48
     * @param string        $xValue              The session value
49
     *
50
     * @return void
51
     */
52
    /* public function flash($sKey, $xValue)
0 ignored issues
show
Coding Style introduced by
Block comment text must start on a new line
Loading history...
53
    {
54
    }*/
55
56
    /**
57
     * Check if a session key exists
58
     *
59
     * @param string        $sKey                The session key
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 16 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
60
     *
61
     * @return bool             True if the session key exists, else false
62
     */
63
    public function has($sKey)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
64
    {
65
        return key_exists($sKey, $_SESSION);
66
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
67
68
    /**
69
     * Get data from the session
70
     *
71
     * @param string        $sKey                The session key
0 ignored issues
show
Coding Style introduced by
Expected 5 spaces after parameter name; 16 found
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter type; 8 found
Loading history...
72
     * @param string|null   $xDefault            The default value
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 3 found
Loading history...
73
     *
74
     * @return mixed            The data under the session key, or the $xDefault parameter
75
     */
76
    public function get($sKey, $xDefault = null)
77
    {
78
        return key_exists($sKey, $_SESSION) ? $_SESSION[$sKey] : $xDefault;
79
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
80
81
    /**
82
     * Get all data in the session
83
     *
84
     * @return array             An array of all data in the session
85
     */
86
    public function all()
87
    {
88
        return $_SESSION;
89
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
90
91
    /**
92
     * Delete a session key and its data
93
     *
94
     * @param string        $sKey                The session key
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 16 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
95
     *
96
     * @return void
97
     */
98
    public function delete($sKey)
99
    {
100
        if(key_exists($sKey, $_SESSION))
101
        {
102
            unset($_SESSION[$sKey]);
103
        }
104
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
105
106
    /**
107
     * Delete all data in the session
108
     *
109
     * @return void
110
     */
111
    public function clear()
112
    {
113
        session_unset();
114
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
115
}
116