Completed
Push — master ( f65d8f...4f3de5 )
by Pavel
04:14 queued 01:54
created

Auth::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 1
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
     * Forbidden to create new instances
10
     */
11
    private function __construct() {}
12
13
    /**
14
     * Forbidden to cloned instances
15
     */
16
    private function __clone() {}
17
18
    /**
19
     * @var User
20
     */
21
    private static $user = null;
22
23
    /**
24
     * @param User $user
25
     */
26
    public static function setUser(User $user)
27
    {
28
        self::$user = $user;
29
    }
30
31
    /**
32
     * @return bool
33
     */
34
    public static function checkUser()
35
    {
36
        return !is_null(self::$user);
37
    }
38
39
    /**
40
     * @return User
41
     */
42
    public static function getUser()
43
    {
44
        return self::$user;
45
    }
46
47
    /**
48
     * @return int|null
49
     */
50
    public static function getUserId()
51
    {
52
        if(self::checkUser()){
53
            return self::$user->id;
54
        } else {
55
            return null;
56
        }
57
    }
58
}