Completed
Push — master ( 195b94...7a36f1 )
by Mohamed
04:50
created

LoggedUser::setLoggedUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 2 Features 0
Metric Value
c 2
b 2
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Extensions\Auth;
13
14
use Tinyissue\Model\User;
15
16
/**
17
 * @author Mohamed Alsharaf <[email protected]>
18
 */
19
trait LoggedUser
20
{
21
    /**
22
     * @var mixed
23
     */
24
    protected $loggedUser;
25
26
    /**
27
     * Return instance of the logged user.
28
     *
29
     * @param mixed $user
30
     *
31
     * @return $this
32
     */
33
    public function setLoggedUser($user)
34
    {
35
        $this->loggedUser = $user;
36
37
        return $this;
38
    }
39
40
    /**
41
     * Return instance of the logged user.
42
     *
43
     * @return User
44
     */
45
    public function getLoggedUser()
46
    {
47
        if (null === $this->loggedUser) {
48
            $this->loggedUser = auth()->user();
49
        }
50
51
        if (!$this->loggedUser instanceof User) {
52
            throw new \DomainException('Unable to find a valid instance of logged user.');
53
        }
54
55
        return $this->loggedUser;
56
    }
57
}
58