GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — 2.x (#64)
by Jindřich
07:10
created

SessionAdapter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 41
ccs 0
cts 19
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A set() 0 4 1
A has() 0 4 1
A get() 0 4 1
1
<?php
2
3
namespace Skautis\SessionAdapter;
4
5
/**
6
 * Adapter pro pouziti $_SESSION ve SkautISu
7
 */
8
class SessionAdapter implements AdapterInterface
9
{
10
11
    /**
12
     * @var array
13
     */
14
    protected $session;
15
16
    public function __construct()
0 ignored issues
show
Coding Style introduced by
__construct uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
17
    {
18
        if (!isset($_SESSION["__" . __CLASS__])) {
19
            $_SESSION["__" . __CLASS__] = [];
20
        }
21
22
        $this->session = &$_SESSION["__" . __CLASS__];
23
    }
24
25
    /**
26
     * @inheritdoc
27
     */
28
    public function set($name, $object)
29
    {
30
        $this->session[$name] = $object;
31
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36
    public function has($name)
37
    {
38
        return isset($this->session[$name]);
39
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44
    public function get($name)
45
    {
46
        return $this->session[$name];
47
    }
48
}
49