Test Failed
Push — master ( 2c9ee3...22d22f )
by Gabriel
03:36
created

UserTrait   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Test Coverage

Coverage 29.17%

Importance

Changes 0
Metric Value
dl 0
loc 52
ccs 7
cts 24
cp 0.2917
rs 10
c 0
b 0
f 0
wmc 8
lcom 2
cbo 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getIdentifier() 0 7 2
A checkAccessToken() 0 8 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
    public function checkAccessToken()
46
    {
47
        if (empty($this->access_token)) {
48
            $token = $this->token();
49
            $this->access_token = $token->getIdentifier();
50
            $this->access_jwt = $token->convertToJWT(app('hello.keys.private'))->__toString();
51
        }
52
    }
53
54 2
    protected function initIdentifier()
55
    {
56 2
        $this->setIdentifier(UsersResolvers::identifier($this));
57 2
    }
58
59
    /**
60
     * @return \ByTIC\Hello\Models\AccessTokens\Token|null
61
     */
62
    protected function generateToken()
63
    {
64
        $userTokens = ModelsHelper::accessTokens()->getValidUserTokens($this, ClientsManager::get());
65
        if (count($userTokens) < 1) {
66
            return $this->createToken($this->generateTokenName());
67
        }
68
        return $userTokens->current();
69
    }
70
}
71