Completed
Push — master ( 592643...f454c2 )
by Michael
03:05 queued 01:21
created

Session   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 79
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A set() 0 4 1
A get() 0 8 2
A del() 0 4 1
A destroy() 0 5 1
A getInstance() 0 9 2
1
<?php
2
3
namespace XoopsModules\Xnewsletter;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
/**
15
 *  Session class
16
 *
17
 * @copyright       The XUUPS Project http://sourceforge.net/projects/xuups/
18
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
19
 * @package         xnewsletter
20
 * @since           1.3
21
 * @author          trabis <[email protected]>
22
 * @author          Harry Fuecks (PHP Anthology Volume II)
23
 */
24
require_once dirname(__DIR__) . '/include/common.php';
25
26
/**
27
 * Class Session
28
 */
29
class Session
30
{
31
    /**
32
     * Session constructor<br>
33
     * Starts the session with session_start()
34
     * <strong>Note:</strong> that if the session has already started,
35
     * session_start() does nothing
36
     */
37
    protected function __construct()
38
    {
39
        @session_start();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
40
    }
41
42
    /**
43
     * Sets a session variable
44
     *
45
     * @param string $name  name of variable
46
     * @param mixed  $value value of variable
47
     *
48
     * @access public
49
     */
50
    public function set($name, $value)
51
    {
52
        $_SESSION[$name] = $value;
53
    }
54
55
    /**
56
     * Fetches a session variable
57
     *
58
     * @param string $name name of variable
59
     *
60
     * @return mixed value of session variable
61
     * @access public
62
     */
63
    public function get($name)
64
    {
65
        if (isset($_SESSION[$name])) {
66
            return $_SESSION[$name];
67
        }
68
69
        return false;
70
    }
71
72
    /**
73
     * Deletes a session variable
74
     *
75
     * @param string $name name of variable
76
     *
77
     * @access public
78
     */
79
    public function del($name)
80
    {
81
        unset($_SESSION[$name]);
82
    }
83
84
    /**
85
     * Destroys the whole session
86
     *
87
     * @access public
88
     */
89
    public function destroy()
90
    {
91
        $_SESSION = [];
92
        session_destroy();
93
    }
94
95
    /**
96
     * @return Session
97
     */
98
    public static function getInstance()
99
    {
100
        static $instance;
101
        if (null === $instance) {
102
            $instance = new static();
103
        }
104
105
        return $instance;
106
    }
107
}
108