Session   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 30
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSession() 0 14 2
A destroy() 0 4 1
A commit() 0 4 1
1
<?php
2
3
namespace cvweiss\projectbase;
4
5
class Session
6
{
7
    private static $session = null;
8
    private static $segment = null;
9
10
    public static function getSession($segmentName = __NAMESPACE__)
0 ignored issues
show
Coding Style introduced by
getSession uses the super-global variable $_COOKIE 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...
11
    {
12
        if (self::$segment === null) {
13
            $sessionTimeout = (int) Config::getInstance()->get("session_timeout", 3600);
14
15
            session_set_save_handler(new RedisSessionHandler(), true);
16
            $sessionFactory = new \Aura\Session\SessionFactory;
17
18
            self::$session = $sessionFactory->newInstance($_COOKIE);
19
            self::$session->setCookieParams(['lifetime' => $sessionTimeout, 'secure' => true, 'httponly' => true]);
20
            self::$segment = self::$session->getSegment($segmentName);
21
        }
22
        return self::$segment;
23
    }
24
25
    public static function destroy()
26
    {
27
        self::$session->destroy();
28
    }
29
30
    public static function commit()
31
    {
32
        self::$session->commit();
33
    }
34
}
35