ApiGenerateTokenFromObjectTask   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A run() 0 10 2
1
<?php
2
3
namespace App\Containers\Authentication\Tasks;
4
5
use App\Containers\Authentication\Adapters\JwtAuthAdapter;
6
use App\Containers\Authentication\Exceptions\AuthenticationFailedException;
7
use App\Ship\Parents\Tasks\Task;
8
use Exception;
9
10
/**
11
 * Class ApiGenerateTokenFromObjectTask.
12
 *
13
 * @author Mahmoud Zalt <[email protected]>
14
 */
15
class ApiGenerateTokenFromObjectTask extends Task
16
{
17
18
    /**
19
     * @var \App\Containers\Authentication\Adapters\JwtAuthAdapter
20
     */
21
    private $jwtAuthAdapter;
22
23
    /**
24
     * ApiLoginThisUserObjectTask constructor.
25
     *
26
     * @param \App\Containers\Authentication\Adapters\JwtAuthAdapter $jwtAuthAdapter
27
     */
28
    public function __construct(JwtAuthAdapter $jwtAuthAdapter)
29
    {
30
        $this->jwtAuthAdapter = $jwtAuthAdapter;
31
    }
32
33
    /**
34
     * @param $user
35
     *
36
     * @return  mixed
37
     */
38
    public function run($user)
39
    {
40
        try {
41
            $token = $this->jwtAuthAdapter->fromUser($user);
42
        } catch (Exception $e) {
43
            throw (new AuthenticationFailedException())->debug($e);
44
        }
45
46
        return $token;
47
    }
48
49
}
50