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
Branch master (9f36d7)
by w3l
02:08
created

Session::session_isset()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 14
c 1
b 0
f 0
rs 9.2
cc 4
eloc 10
nc 3
nop 1
1
<?php
2
namespace 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 session_set($name, $content, $expires = 86400) {
0 ignored issues
show
Coding Style introduced by
session_set 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 session_isset($name) {
0 ignored issues
show
Coding Style introduced by
session_isset 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 session_read($name) {
0 ignored issues
show
Coding Style introduced by
session_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...
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 session_delete($name) {
0 ignored issues
show
Coding Style introduced by
session_delete 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
}