__construct()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Maztech\PersistentData;
4
5
use Maztech\Exceptions\InstagramSDKException;
6
7
/**
8
 * Class InstagramSessionPersistentDataHandler
9
 *
10
 * @package Instagram
11
 */
12
class InstagramSessionPersistentDataHandler implements PersistentDataInterface
13
{
14
    /**
15
     * @var string Prefix to use for session variables.
16
     */
17
    protected $sessionPrefix = 'FBRLH_';
18
19
    /**
20
     * Init the session handler.
21
     *
22
     * @param boolean $enableSessionCheck
23
     *
24
     * @throws InstagramSDKException
25
     */
26
    public function __construct($enableSessionCheck = true)
27
    {
28
        if ($enableSessionCheck && session_status() !== PHP_SESSION_ACTIVE) {
29
            throw new InstagramSDKException(
30
                'Sessions are not active. Please make sure session_start() is at the top of your script.',
31
                720
32
            );
33
        }
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public function get($key)
40
    {
41
        if (isset($_SESSION[$this->sessionPrefix . $key])) {
42
            return $_SESSION[$this->sessionPrefix . $key];
43
        }
44
45
        return null;
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51
    public function set($key, $value)
52
    {
53
        $_SESSION[$this->sessionPrefix . $key] = $value;
54
    }
55
}
56