CSession   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 86.96%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 10
c 4
b 0
f 0
lcom 1
cbo 1
dl 0
loc 91
rs 10
ccs 20
cts 23
cp 0.8696

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A start() 0 4 1
A set() 0 4 1
A has() 0 4 1
A name() 0 10 3
A get() 0 6 3
1
<?php
2
3
namespace Anax\Session;
4
5
/**
6
 * Anax base class for wrapping sessions.
7
 *
8
 */
9
class CSession
10
{
11
    use \Anax\TConfigure;
12
13
14
15
    /**
16
     * Construct session.
17
     *
18
     * @param array $options to configure options.
19
     */
20 4
    public function __construct($options = [])
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
    {
22 4
        ;
23 4
    }
24
25
26
27
    /**
28
     * Set a session name or use one from config.
29
     *
30
     * @param array $aName to set as session name, default is null and then use name from config.
31
     */
32 2
    public function name($aName = null)
33
    {
34 2
        $name = isset($aName)
35 2
            ? $aName
36 2
            : (isset($this->config['name'])
37 1
                ? $this->config['name']
38 2
                : "anax");
39
40 2
        session_name($name);
41 2
    }
42
43
44
    /**
45
     * Start session.
46
     *
47
     * @param array $options to configure options.
48
     */
49
    public function start($options = [])
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
    {
51
        session_start();
52
    }
53
54
55
56
    /**
57
     * Get values from session.
58
     *
59
     * @param string $key     in session variable.
60
     * @param mixed  $default default value to return when key is not set in session.
61
     *
62
     * @return mixed
63
     */
64 1
    public function get($key, $default = null)
65
    {
66 1
        return isset($_SESSION) && isset($_SESSION[$key])
67 1
            ? $_SESSION[$key]
68 1
            : $default;
69
    }
70
71
72
73
    /**
74
     * Set values in session.
75
     *
76
     * @param string $key   in session variable.
77
     * @param mixed  $value to set in session.
78
     *
79
     * @return void
80
     */
81 1
    public function set($key, $value)
82
    {
83 1
        $_SESSION[$key] = $value;
84 1
    }
85
86
87
88
    /**
89
     * Check if a value is set in the session.
90
     *
91
     * @param string $key   in session variable.
92
     *
93
     * @return boolean true if $key is set, else false.
94
     */
95 1
    public function has($key)
96
    {
97 1
        return isset($_SESSION[$key]);
98
    }
99
}
100