Test Failed
Push — master ( a6b51e...5fffdb )
by Gabriel
08:05
created

UserTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Test Coverage

Coverage 38.89%

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
ccs 7
cts 18
cp 0.3889
wmc 6
lcom 2
cbo 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getIdentifier() 0 7 2
A initIdentifier() 0 4 1
A generateToken() 0 8 2
1
<?php
2
3
namespace ByTIC\Hello\Models\Users\Traits;
4
5
use ByTIC\Auth\Models\Users\Traits\AbstractUserTrait;
6
use ByTIC\Hello\Models\Clients\PersonalAccess\ClientsManager;
7
use ByTIC\Hello\Models\Traits\HasApiTokensTrait;
8
use ByTIC\Hello\Models\Users\Resolvers\UsersResolvers;
9
use ByTIC\Hello\Utility\ModelsHelper;
10
use League\OAuth2\Server\Entities\Traits\EntityTrait;
11
12
/**
13
 * Trait UserTrait
14
 * @package ByTIC\Hello\Models\Users\
15
 *
16
 * @property string $access_token
17
 * @property string $access_jwt
18
 */
19
trait UserTrait
20
{
21
    use AbstractUserTrait {
22
        doAuthentication as doAuthenticationTrait;
23
    }
24
    use HasApiTokensTrait, EntityTrait;
25
26
    /**
27
     * @return string
28
     */
29 3
    public function getIdentifier()
30
    {
31 3
        if (empty($this->identifier)) {
32 2
            $this->initIdentifier();
33
        }
34 3
        return $this->identifier;
35
    }
36
37
    public function doAuthentication()
38
    {
39
        $token = $this->token();
40
        $this->access_token = $token->getIdentifier();
41
        $this->access_jwt = $token->convertToJWT(app('hello.keys.private'))->__toString();
42
        $this->doAuthenticationTrait();
0 ignored issues
show
Bug introduced by
The method doAuthenticationTrait() does not exist on ByTIC\Hello\Models\Users\Traits\UserTrait. Did you maybe mean doAuthentication()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
43
    }
44
45 2
    protected function initIdentifier()
46
    {
47 2
        $this->setIdentifier(UsersResolvers::identifier($this));
48 2
    }
49
50
    /**
51
     * @return \ByTIC\Hello\Models\AccessTokens\Token|null
52
     */
53
    protected function generateToken()
54
    {
55
        $userTokens = ModelsHelper::accessTokens()->getValidUserTokens($this, ClientsManager::get());
56
        if (count($userTokens) < 1) {
57
            return $this->createToken($this->generateTokenName());
58
        }
59
        return $userTokens->current();
60
    }
61
}
62