SessionStorage   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 34.04 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 82.61%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 16
loc 47
ccs 19
cts 23
cp 0.8261
rs 10
c 3
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A set() 0 7 1
A get() 7 7 2
A clear() 9 9 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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