Session   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 20
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __destruct() 0 3 1
A restore() 0 6 3
1
<?php
2
3
/**
4
 * This file is part of Lenius Basket, a PHP package to handle
5
 * your shopping basket.
6
 *
7
 * Copyright (c) 2017 Lenius.
8
 * https://github.com/lenius/basket
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 *
13
 * @author Carsten Jonstrup<[email protected]>
14
 * @copyright 2017 Lenius.
15
 *
16
 * @version production
17
 *
18
 * @see https://github.com/lenius/basket
19
 */
20
21
namespace Lenius\Basket\Storage;
22
23
use Lenius\Basket\StorageInterface;
24
25
/**
26
 * Class Session.
27
 */
28
class Session extends Runtime implements StorageInterface
29
{
30
    /**
31
     * The Session store constructor.
32
     */
33
    public function restore(): void
34
    {
35
        session_id() || session_start();
36
37
        if (isset($_SESSION['cart'])) {
38
            static::$cart = (array) unserialize($_SESSION['cart']);
39
        }
40
    }
41
42
    /**
43
     * The session store destructor.
44
     */
45
    public function __destruct()
46
    {
47
        $_SESSION['cart'] = serialize(static::$cart);
48
    }
49
}
50