FacebookCakeSessionPersistentDataHandler::set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 2
dl 0
loc 2
rs 10
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
namespace WrDX\Facebook;
4
5
/**
6
 * Class FacebookCakeSessionPersistentDataHandler
7
 */
8
class FacebookCakeSessionPersistentDataHandler implements \Facebook\PersistentData\PersistentDataInterface {
9
10
    /**
11
     * @var object Session handler
12
     */
13
    private $_CakeSession;
14
15
    /**
16
     * @var string Prefix to use for session variables.
17
     */
18
    protected $sessionPrefix = null;
19
20
    /**
21
     * FacebookCakeSessionPersistentDataHandler constructor.
22
     *
23
     * @param object $CakeSession
24
     * @param bool   $enableSessionCheck
25
     * @param string $sessionPrefix
26
     *
27
     * @throws \Facebook\Exceptions\FacebookSDKException
28
     */
29 4
    public function __construct($CakeSession, $enableSessionCheck = true, $sessionPrefix = 'Facebook.php-graph-sdk') {
30
31 4
        $this->_CakeSession = $CakeSession;
32
33
        # Session check
34 4
        if ($enableSessionCheck && ( ! $this->_CakeSession->valid() || ! $this->_CakeSession->started())) {
35 1
            throw new \Facebook\Exceptions\FacebookSDKException('Sessions are not active.', 720);
36
        }
37
38 3
        $this->sessionPrefix = $sessionPrefix . '.';
39
40 3
    }
41
42
    /**
43
     * Get a value from a persistent data store
44
     *
45
     * @param string $key
46
     *
47
     * @return mixed
48
     */
49 2
    public function get($key) {
50 2
        return $this->_CakeSession->read($this->sessionPrefix . $key);
51
    }
52
53
    /**
54
     * Set a value in the persistent data store
55
     *
56
     * @param string $key
57
     * @param mixed  $value
58
     *
59
     * @return mixed
60
     */
61 1
    public function set($key, $value) {
62 1
        return $this->_CakeSession->write($this->sessionPrefix . $key, $value);
63
    }
64
65
}
66