Passed
Push — master ( 7c83a0...cd350b )
by Thierry
02:08
created

SessionManager   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 107
rs 10
c 0
b 0
f 0
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 1
A has() 0 3 1
A getId() 0 3 1
A all() 0 3 1
A set() 0 3 1
A delete() 0 5 2
A clear() 0 3 1
A newId() 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 SessionManager implements SessionContract
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class SessionManager
Loading history...
8
{
9
    /**
10
     * Get the current session id
11
     *
12
     * @return string
13
     */
14
    public function getId(): string
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 name; 4 found
Loading history...
23
     *
24
     * @return void
25
     */
26
    public function newId(bool $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; 4 found
Loading history...
35
     * @param mixed $xValue    The session value
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
36
     *
37
     * @return void
38
     */
39
    public function set(string $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 mixed $xValue    The session value
49
     *
50
     * @return void
51
     */
52
    /* public function flash(string $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; 4 found
Loading history...
60
     *
61
     * @return bool
62
     */
63
    public function has(string $sKey): bool
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
64
    {
65
        return isset($_SESSION[$sKey]);
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; 4 found
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter type; 1 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; 4 found
Loading history...
73
     *
74
     * @return mixed
75
     */
76
    public function get(string $sKey, $xDefault = null)
77
    {
78
        return $_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
85
     */
86
    public function all(): array
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; 4 found
Loading history...
95
     *
96
     * @return void
97
     */
98
    public function delete(string $sKey)
99
    {
100
        if(isset($_SESSION[$sKey]))
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