Completed
Push — master ( e93f60...2f787f )
by Mahmoud
08:56 queued 02:41
created

ApiLogoutTask   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A run() 0 13 2
1
<?php
2
3
namespace App\Containers\Authentication\Tasks;
4
5
use App\Containers\Authentication\Adapters\JwtAuthAdapter;
6
use App\Containers\Authentication\Exceptions\MissingTokenException;
7
use App\Port\Task\Abstracts\Task;
8
9
/**
10
 * Class ApiLogoutTask.
11
 *
12
 * @author Mahmoud Zalt <[email protected]>
13
 */
14
class ApiLogoutTask extends Task
15
{
16
17
    /**
18
     * @var \App\Containers\Authentication\Adapters\JwtAuthAdapter
19
     */
20
    private $jwtAuthAdapter;
21
22
    /**
23
     * ApiLogoutTask constructor.
24
     *
25
     * @param \App\Containers\Authentication\Adapters\JwtAuthAdapter $jwtAuthAdapter
26
     */
27
    public function __construct(JwtAuthAdapter $jwtAuthAdapter)
28
    {
29
        $this->jwtAuthAdapter = $jwtAuthAdapter;
30
    }
31
32
    /**
33
     * @param $authorizationHeader
34
     *
35
     * @throws \App\Containers\Authentication\Tasks\MissingTokenException
36
     *
37
     * @return bool
38
     */
39
    public function run($authorizationHeader)
40
    {
41
        // remove the `Bearer` string from the header and keep only the token
42
        $token = str_replace('Bearer', '', $authorizationHeader);
43
44
        $ok = $this->jwtAuthAdapter->invalidate($token);
45
46
        if (!$ok) {
47
            throw new MissingTokenException();
48
        }
49
50
        return true;
51
    }
52
53
}
54