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.

Session   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A sessionSet() 0 4 1
A sessionIsset() 0 11 4
A sessionRead() 0 4 1
A sessionDelete() 0 4 1
1
<?php
2
/**
3
 * Session.php
4
 */
5
namespace w3l\Holt45;
6
7
/**
8
 * Set/Check/Read/Delete sessions(with automatic "expire" of session after x seconds).
9
 */
10
trait Session
11
{
12
    /**
13
     * Handle sessions - set session
14
     *
15
     * @param string $name Session name
16
     * @param string $content Session content
17
     * @param int $expires How many seconds before the session should expire.
18
     */
19
    public static function sessionSet($name, $content, $expires = 86400)
0 ignored issues
show
Coding Style introduced by
sessionSet 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...
20
    {
21
        $_SESSION[$name] = (time() + $expires).'-'.$content;
22
    }
23
24
    /**
25
     * Handle sessions - check if session is set and not expired.
26
     *
27
     * @param string $name Session name
28
     * @return bool Session status
29
     */
30
    public static function sessionIsset($name)
0 ignored issues
show
Coding Style introduced by
sessionIsset 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...
31
    {
32
        if (isset($_SESSION[$name])) {
33
            $expires = current(explode("-", $_SESSION[$name]));
34
            if (ctype_digit($expires) && $expires > time()) {
35
                return true;
36
            }
37
            unset($_SESSION[$name]);
38
        }
39
        return false;
40
    }
41
42
    /**
43
     * Handle sessions - Get session content
44
     *
45
     * @param string $name Session name
46
     * @return string Session content
47
     */
48
    public static function sessionRead($name)
0 ignored issues
show
Coding Style introduced by
sessionRead 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...
49
    {
50
        return substr(strstr($_SESSION[$name], '-'), 1);
51
    }
52
53
    /**
54
     * Handle sessions - Delete session
55
     *
56
     * @param string $name Session name
57
     * @return void
58
     */
59
    public static function sessionDelete($name)
0 ignored issues
show
Coding Style introduced by
sessionDelete 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...
60
    {
61
        unset($_SESSION[$name]);
62
    }
63
}
64