SessionStorage::clear()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 7
cts 7
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Happyr\LinkedIn\Storage;
4
5
/**
6
 * Store data in the global session.
7
 *
8
 * @author Tobias Nyholm <[email protected]>
9
 */
10
class SessionStorage extends BaseDataStorage
11
{
12 8
    public function __construct()
13
    {
14
        //start the session if it not already been started
15 8
        if (php_sapi_name() !== 'cli') {
16
            if (session_id() === '') {
17
                session_start();
18
            }
19
        }
20 8
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 2
    public function set($key, $value)
26
    {
27 2
        $this->validateKey($key);
28
29 1
        $name = $this->getStorageKeyId($key);
30 1
        $_SESSION[$name] = $value;
31 1
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 1 View Code Duplication
    public function get($key)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
    {
38 1
        $this->validateKey($key);
39 1
        $name = $this->getStorageKeyId($key);
40
41 1
        return isset($_SESSION[$name]) ? $_SESSION[$name] : null;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 2 View Code Duplication
    public function clear($key)
48
    {
49 2
        $this->validateKey($key);
50
51 1
        $name = $this->getStorageKeyId($key);
52 1
        if (isset($_SESSION[$name])) {
53 1
            unset($_SESSION[$name]);
54 1
        }
55 1
    }
56
}
57