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
Push — dev ( b6442a...4385af )
by w3l
06:19
created

Session::sessionRead()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace w3l\Holt45;
3
trait Session {
4
5
	/**
6
	 * Handle sessions - set session
7
	 *
8
	 * @param string $name Session name
9
	 * @param string $content Session content
10
	 * @param int $expires How many seconds before the session should expire.
11
	 */
12
	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...
13
		$_SESSION[$name] = (time() + $expires).'-'.$content;
14
	}
15
16
	/**
17
	 * Handle sessions - check if session is set and not expired.
18
	 *
19
	 * @param string $name Session name
20
	 * @return bool Session status
21
	 */
22
	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...
23
		if(isset($_SESSION[$name])) {
24
			$expires = current(explode("-",$_SESSION[$name]));
25
			if(ctype_digit($expires) && $expires > time()) {
26
				return true;
27
				
28
			} else {
29
				unset($_SESSION[$name]);
30
				return false;
31
			}
32
		} else {
33
			return false;
34
		}
35
	}
36
37
	/**
38
	 * Handle sessions - Get session content
39
	 *
40
	 * @param string $name Session name
41
	 * @return string Session content
42
	 */
43
	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...
44
		return substr(strstr($_SESSION[$name], '-'),1);
45
	}
46
47
	/**
48
	 * Handle sessions - Delete session
49
	 *
50
	 * @param string $name Session name
51
	 * @return void
52
	 */
53
	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...
54
		unset($_SESSION[$name]);
55
	}
56
57
}