Session   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 7
dl 0
loc 18
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fetch() 0 2 2
A store() 0 2 1
A __construct() 0 5 3
1
<?php
2
3
namespace evelikto\di\storage\impl;
4
use evelikto\di\storage\OfflineStorage;
5
6
/** Session storage implementation */
7
class Session implements OfflineStorage
8
{
9
    /** Just ensure the preconditions - session is active and started */
10
    public function __construct() {
11
        if (session_status() === PHP_SESSION_NONE)
12
            session_start();
13
        else if (session_status() === PHP_SESSION_DISABLED)
14
            throw new SessionsNotEnabled();
15
    }
16
17
    /** {@inheritdoc} */
18
    public function fetch(string $key) {
19
        return isset($_SESSION[$key]) ? unserialize($_SESSION[$key]) : null;
20
    }
21
22
    /** {@inheritdoc} */
23
    public function store(string $key, $value) {
24
        $_SESSION[$key] = serialize($value);
25
    }
26
}