Completed
Push — master ( 28c43d...5a5893 )
by Mahmoud
10:56 queued 07:20
created

ApiLogoutTask::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 13
loc 13
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
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
8
/**
9
 * Class ApiLogoutTask.
10
 *
11
 * @author Mahmoud Zalt <[email protected]>
12
 */
13
class ApiLogoutTask
14
{
15
16
    /**
17
     * @var \App\Containers\Authentication\Adapters\JwtAuthAdapter
18
     */
19
    private $jwtAuthAdapter;
20
21
    /**
22
     * ApiLogoutTask constructor.
23
     *
24
     * @param \App\Containers\Authentication\Adapters\JwtAuthAdapter $jwtAuthAdapter
25
     */
26
    public function __construct(JwtAuthAdapter $jwtAuthAdapter)
27
    {
28
        $this->jwtAuthAdapter = $jwtAuthAdapter;
29
    }
30
31
    /**
32
     * @param $authorizationHeader
33
     *
34
     * @throws \App\Containers\Authentication\Tasks\MissingTokenException
35
     *
36
     * @return bool
37
     */
38 View Code Duplication
    public function run($authorizationHeader)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        // remove the `Bearer` string from the header and keep only the token
41
        $token = str_replace('Bearer', '', $authorizationHeader);
42
43
        $ok = $this->jwtAuthAdapter->invalidate($token);
44
45
        if (!$ok) {
46
            throw new MissingTokenException();
47
        }
48
49
        return true;
50
    }
51
52
}
53