Session::restore()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 4
nop 0
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 12
rs 10
c 0
b 0
f 0
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