Completed
Push — master ( 1b2d0a...89ea1a )
by Oscar
03:00
created

PhpSession::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Psr7Middlewares\Storage;
4
5
use Psr7Middlewares\Middleware;
6
7
/**
8
 * Wrapper for PHP sessions
9
 */
10
class PhpSession implements StorageInterface
11
{
12
    protected $storage;
13
14
    public function __construct(array &$storage)
15
    {
16
        if (!isset($storage[Middleware::KEY])) {
17
            $storage[Middleware::KEY] = [];
18
        }
19
20
        $this->storage =& $storage[Middleware::KEY];
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function get($key)
27
    {
28
        return isset($this->storage[$key]) ? $this->storage[$key] : null;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function set($key, $value)
35
    {
36
        $this->storage[$key] = $value;
37
    }
38
}
39