Auth::getUser()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace App\Common;
3
4
use App\Model\User;
5
6
final class Auth
7
{
8
    /**
9
     * @var User
10
     */
11
    private static $user = null;
12
13
    /**
14
     * Forbidden to create new instances
15
     */
16
    private function __construct()
17
    {
18
19
    }
20
21
    /**
22
     * Forbidden to cloned instances
23
     */
24
    private function __clone()
25
    {
26
27
    }
28
29
    /**
30
     * @param User $user
31
     */
32
    public static function setUser(User $user)
33
    {
34
        self::$user = $user;
35
    }
36
37
    /**
38
     * @return bool
39
     */
40
    public static function checkUser()
41
    {
42
        return !is_null(self::$user);
43
    }
44
45
    /**
46
     * @return User
47
     */
48
    public static function getUser()
49
    {
50
        return self::$user;
51
    }
52
53
    /**
54
     * @return int|null
55
     */
56
    public static function getUserId()
57
    {
58
        if (self::checkUser()) {
59
            return self::$user->id;
60
        } else {
61
            return null;
62
        }
63
    }
64
}
65