Completed
Push — master ( 4b04e0...ecec2c )
by Gabriel
10:34 queued 05:21
created

UserTrait::doAuthentication()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 6
rs 10
ccs 0
cts 5
cp 0
cc 1
nc 1
nop 0
crap 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 1
            $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();
0 ignored issues
show
Bug introduced by
app('hello.keys.private') of type Nip\Container\Container is incompatible with the type League\OAuth2\Server\CryptKey expected by parameter $privateKey of ByTIC\Hello\Models\Acces...s\Token::convertToJWT(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
        $this->access_jwt = $token->convertToJWT(/** @scrutinizer ignore-type */ app('hello.keys.private'))->__toString();
Loading history...
Unused Code introduced by
The call to app() has too many arguments starting with 'hello.keys.private'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
        $this->access_jwt = $token->convertToJWT(/** @scrutinizer ignore-call */ app('hello.keys.private'))->__toString();

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
42
        $this->doAuthenticationTrait();
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();
0 ignored issues
show
Unused Code introduced by
The call to app() has too many arguments starting with 'hello.keys.private'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
            $this->access_jwt = $token->convertToJWT(/** @scrutinizer ignore-call */ app('hello.keys.private'))->__toString();

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug introduced by
app('hello.keys.private') of type Nip\Container\Container is incompatible with the type League\OAuth2\Server\CryptKey expected by parameter $privateKey of ByTIC\Hello\Models\Acces...s\Token::convertToJWT(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
            $this->access_jwt = $token->convertToJWT(/** @scrutinizer ignore-type */ app('hello.keys.private'))->__toString();
Loading history...
51
        }
52
    }
53
54 1
    protected function initIdentifier()
55
    {
56 1
        $this->setIdentifier(UsersResolvers::identifier($this));
0 ignored issues
show
Bug introduced by
$this of type ByTIC\Hello\Models\Users\Traits\UserTrait is incompatible with the type Nip\Records\Record expected by parameter $entity of ByTIC\Hello\Models\Users...Resolvers::identifier(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

56
        $this->setIdentifier(UsersResolvers::identifier(/** @scrutinizer ignore-type */ $this));
Loading history...
57 1
    }
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();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $userTokens->current() also could return the type Nip\Records\AbstractMode...ections\Collection|true which is incompatible with the documented return type ByTIC\Hello\Models\AccessTokens\Token|null.
Loading history...
69
    }
70
}
71