FacebookCakeSessionPersistentDataHandler   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 9
c 4
b 0
f 0
dl 0
loc 55
rs 10
ccs 10
cts 10
cp 1
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 2 1
A get() 0 2 1
A __construct() 0 10 4
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