Completed
Push — master ( 8f456d...28c43d )
by Mahmoud
07:45 queued 03:24
created

GetAuthenticatedUserTask::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace App\Containers\Authentication\Tasks;
4
5
use App\Containers\Authentication\Exceptions\AuthenticationFailedException;
6
use App\Port\Task\Abstracts\Task;
7
use Illuminate\Auth\AuthManager as Auth;
8
9
/**
10
 * Class GetAuthenticatedUserTask.
11
 *
12
 * @author Mahmoud Zalt <[email protected]>
13
 */
14
class GetAuthenticatedUserTask extends Task
15
{
16
17
    /**
18
     * @var  \App\Containers\User\Tasks\Auth
19
     */
20
    private $auth;
21
22
    /**
23
     * GetAuthenticatedUserTask constructor.
24
     *
25
     * @param \App\Containers\User\Tasks\Auth $auth
26
     */
27
    public function __construct(Auth $auth)
28
    {
29
        $this->auth = $auth;
0 ignored issues
show
Documentation Bug introduced by
It seems like $auth of type object<Illuminate\Auth\AuthManager> is incompatible with the declared type object<App\Containers\User\Tasks\Auth> of property $auth.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
30
    }
31
32
    /**
33
     * get the user object of the current authenticated user.
34
     * If token was passed as param then inject it in the returned user object.
35
     *
36
     * @param null $token
37
     *
38
     * @return mixed
39
     */
40
    public function run($token = null)
41
    {
42
        if (!$user = $this->auth->user()) {
43
            throw new AuthenticationFailedException('User is not logged in.');
44
        }
45
46
        return $token ? $user->injectToken($token) : $user;
47
    }
48
49
}
50