Session::put()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Session Class Doc Comment
4
 *
5
 * PHP version 5
6
 *
7
 * @category PHP
8
 * @package  OpenChat
9
 * @author   Ankit Jain <[email protected]>
10
 * @license  The MIT License (MIT)
11
 * @link     https://github.com/ankitjain28may/openchat
12
 */
13
namespace ChatApp;
14
15
@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...
16
17
/**
18
 * Session Management
19
 *
20
 * @category PHP
21
 * @package  OpenChat
22
 * @author   Ankit Jain <[email protected]>
23
 * @license  The MIT License (MIT)
24
 * @link     https://github.com/ankitjain28may/openchat
25
 */
26
class Session
27
{
28
    /*
29
    |--------------------------------------------------------------------------
30
    | Session Class
31
    |--------------------------------------------------------------------------
32
    |
33
    | For Fetching the sidebar results.
34
    |
35
    */
36
37
    /**
38
     * Create Key-Value pain in session storage
39
     *
40
     * @param int $key   To store key for the value
41
     * @param int $value To store value for the corresponding key
42
     *
43
     * @return void
44
     */
45
    public static function put($key, $value)
46
    {
47
        $_SESSION[$key] = $value;
48
    }
49
50
    /**
51
     * Get Value from the session storage
52
     *
53
     * @param int $key To store key for the value
54
     *
55
     * @return string or null
56
     */
57
    public static function get($key)
58
    {
59
        return (isset($_SESSION[$key]) ? $_SESSION[$key] : null);
60
    }
61
62
    /**
63
     * Destroy key-value pair from the session storage
64
     *
65
     * @param int $key To store key for the value
66
     *
67
     * @return void
68
     */
69
    public static function forget($key)
70
    {
71
        unset($_SESSION[$key]);
72
    }
73
74
}
75