JwtAuth   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 1
dl 51
loc 51
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getUser() 4 4 1
A __construct() 5 5 1
A getUserFieldValue() 6 6 3

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 namespace Sofa\Revisionable\Adapters;
2
3
4
use Sofa\Revisionable\UserProvider;
5
use Tymon\JWTAuth\JWTAuth as JWT;
6
7 View Code Duplication
class JwtAuth implements UserProvider
0 ignored issues
show
Duplication introduced by
This class 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...
8
{
9
10
    /**
11
     * Auth provider instance.
12
     *
13
     * @var \Tymon\JWTAuth\JWTAuth
14
     */
15
    protected $provider;
16
17
    /**
18
     * Field from the user to be saved as author of the action.
19
     *
20
     * @var string
21
     */
22
    protected $field;
23
24
    /**
25
     * Create adapter instance for Illuminate Guard.
26
     *
27
     * @param \Tymon\JWTAuth\JWTAuth $provider
28
     * @param string $field
29
     */
30
    public function __construct(JWT $provider, $field = null)
31
    {
32
        $this->provider = $provider;
33
        $this->field = $field;
34
    }
35
36
    /**
37
     * Get identifier of the currently logged in user.
38
     *
39
     * @return string|null
40
     */
41
    public function getUser()
42
    {
43
        return $this->getUserFieldValue();
44
    }
45
46
    /**
47
     * Get value from the user to be saved as the author.
48
     *
49
     * @return string|null
50
     */
51
    protected function getUserFieldValue()
52
    {
53
        if ($user = $this->provider->parseToken()->toUser()) {
54
            return ($field = $this->field) ? (string)$user->{$field} : $this->provider->getIdentifier();
55
        }
56
    }
57
}