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.

FlashData::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace Nip\FlashData;
4
5
/**
6
 * Nip Framework
7
 *
8
 * LICENSE
9
 *
10
 * This source file is subject to the license that is bundled
11
 * with this package in the file LICENSE.txt.
12
 *
13
 * @category   Nip
14
 * @copyright  2009 Nip Framework
15
 * @version    SVN: $Id: Flash.php 14 2009-04-13 11:24:22Z victor.stanciu $
16
 */
17
18
class FlashData
19
{
20
21
    protected $previous = [];
22
    protected $next = [];
23
24
    protected $session_var = 'flash-data';
25
26
    /**
27
     * FlashData constructor.
28
     */
29
    public function __construct()
30
    {
31
        $this->read();
32
    }
33
34
    public function read()
0 ignored issues
show
Coding Style introduced by
read 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...
35
    {
36
        if (isset($_SESSION[$this->session_var])) {
37
            $data = $_SESSION[$this->session_var];
38
            if (is_array($data)) {
39
                $this->previous = $data;
40
            }
41
            unset($_SESSION[$this->session_var]);
42
        }
43
    }
44
45
    public function has($var)
46
    {
47
        return isset($this->previous[trim($var)]) ? true : false;
48
    }
49
50
    public function get($var)
51
    {
52
        return isset($this->previous[trim($var)]) ? $this->previous[trim($var)] : null;
53
    }
54
55 1
    public function add($var, $value)
56
    {
57 1
        $this->next[trim($var)] = $value;
58 1
        $this->write();
59 1
    }
60
61 1
    protected function write()
0 ignored issues
show
Coding Style introduced by
write 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...
62
    {
63 1
        $_SESSION[$this->session_var] = $this->next;
64 1
    }
65
66
    public function remove($var)
67
    {
68
        unset($this->next[trim($var)]);
69
        $this->write();
70
    }
71
72
    protected function clear()
73
    {
74
        $this->next = [];
75
    }
76
}
77