Completed
Push — master ( 22caaa...988d36 )
by Maxime
15:13 queued 03:59
created

UserUtils::securityCheckLockEnabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php namespace Distilleries\Expendable\Helpers;
2
3
use \Auth;
4
use \Session;
5
6
class UserUtils
7
{
8
9 4
    public static function get()
10
    {
11 4
        return Auth::user();
12
    }
13
14 88
    public static function getEmail()
15
    {
16 88
        return Auth::user()->getEmailForPasswordReset();
17
    }
18
19 88
    public static function getDisplayName()
20
    {
21 88
        return Auth::user()->getEmailForPasswordReset();
22
    }
23
24 12
    public static function isNotSuperAdmin()
25
    {
26 12
        return Auth::user()->role->initials != '@sa';
27
    }
28
29
30 24
    public static function setArea($area)
31
    {
32 24
        Session::put('permissions', $area);
33 24
    }
34
35 12
    public static function getArea()
36
    {
37 12
        return Session::get('permissions');
38
    }
39
40 16
    public static function forgotArea()
41
    {
42 16
        Session::forget('permissions');
43 16
    }
44
45 8
    public static function hasAccess($key)
46
    {
47 8
        $key  = ltrim($key, "\\");
48 8
        $area = self::getArea();
49 8
        $area = (is_array($area) && !empty($area)) ? $area : [];
50
51 8
        return in_array($key, $area);
52
    }
53
54 276
    public static function hasDisplayAllStatus()
55
    {
56 276
        return Session::get('display_all_status', false);
57
    }
58
59 16
    public static function forgotDisplayAllStatus()
60
    {
61 16
        Session::forget('display_all_status');
62 16
    }
63
64 16
    public static function setDisplayAllStatus()
65
    {
66 16
        Session::put('display_all_status', true);
67 16
    }
68
69 16
    public static function setIsLoggedIn()
0 ignored issues
show
Coding Style introduced by
setIsLoggedIn 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...
70
    {
71 16
        if (session_id() == '')
72 16
        {
73 4
            @session_start();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
74
75 4
        }
76
77 16
        $_SESSION['isLoggedIn'] = true;
78 16
    }
79
80 16
    public static function forgotIsLoggedIn()
0 ignored issues
show
Coding Style introduced by
forgotIsLoggedIn 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...
81
    {
82 16
        $session_id = session_id();
83
84 16
        if (!empty($session_id))
85 16
        {
86 16
            unset($_SESSION['isLoggedIn']);
87 16
        }
88
89 16
    }
90
91 8
    public static function securityCheckLockEnabled()
92
    {
93 8
        return config('expendable.auth.security_enabled') === true;
94
    }
95
}