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

ApiLogoutTask   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 32.5 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A run() 13 13 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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