Session   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A pop() 0 3 1
A add() 0 3 1
A get() 0 3 1
1
<?php
2
3
namespace mvc\core\http;
4
5
use mvc\core\meta\Singleton;
6
7
class Session extends Singleton
8
{
9
10
    public ?string $flash = null;
11
12
    public function __construct()
13
    {
14
        session_start();
15
16
        if (isset($_SESSION['flash'])) {
17
            $this->flash = $_SESSION['flash'];
18
            $this->pop('flash');
19
        }
20
    }
21
22
    public function add($key, $val)
23
    {
24
        $_SESSION[$key] = $val;
25
    }
26
27
    public function get($key)
28
    {
29
        return $_SESSION[$key] ?? [];
30
    }
31
32
    public function pop($key)
33
    {
34
        unset($_SESSION[$key]);
35
    }
36
}
37