Test Setup Failed
Push — master ( f0f097...c6f3d6 )
by Php Easy Api
04:31
created

UserBuilder::allDeviceTokens()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Resta\Authenticate\Driver\Eloquent;
4
5
use Resta\Authenticate\AuthenticateProvider;
6
use Resta\Authenticate\Driver\BuilderContract;
7
use Resta\Authenticate\Resource\AuthUserManager;
8
use Resta\Authenticate\Driver\BuilderParamGenerator;
9
10
class UserBuilder extends UserBuilderHelper implements BuilderContract
11
{
12
    //get param generator
13
    use BuilderParamGenerator;
0 ignored issues
show
introduced by
The trait Resta\Authenticate\Driver\BuilderParamGenerator requires some properties which are not provided by Resta\Authenticate\Driver\Eloquent\UserBuilder: $id, $token
Loading history...
14
15
    /**
16
     * @var AuthenticateProvider
17
     */
18
    protected $auth;
19
20
    /**
21
     * UserBuilder constructor.
22
     * @param $auth \Resta\Authenticate\AuthenticateProvider
23
     */
24
    public function __construct($auth)
25
    {
26
        //authenticate instance
27
        $this->auth = $auth;
28
29
        parent::__construct();
30
    }
31
32
    /**
33
     * get all device tokens for user
34
     *
35
     * @param AuthUserManager $manager
36
     */
37
    public function allDeviceTokens($manager)
38
    {
39
        return $this->allDeviceTokenQuery($manager);
40
    }
41
42
    /**
43
     * check builder
44
     *
45
     * @param $token
46
     */
47
    public function check($token)
48
    {
49
        // using the driver object we write the query builder statement.
50
        // we do the values of the query with the token that are sent.
51
        $query = $this->checkQuery($token);
52
53
        // with query we bind the returned values to the params property of the auth object.
54
        // and so the auth object will make a final return with these values.
55
        $this->paramValues('check',$query);
56
    }
57
58
    /**
59
     * login builder
60
     *
61
     * @param \Resta\Authenticate\Resource\AuthLoginCredentialsManager $credentials
62
     * @return mixed|void
63
     */
64
    public function login($credentials)
65
    {
66
        // using the driver object we write the query builder statement.
67
        // we do the values of the query with the credentials that are sent.
68
        $query = $this->setQuery($credentials);
69
70
        // with query we bind the returned values to the params property of the auth object.
71
        // and so the auth object will make a final return with these values.
72
        $this->paramValues('login',$query);
73
74
        // we assign the credential hash value
75
        // to the global of the authenticate object.
76
        $this->auth->credentialHash = $credentials->getCredentialHash();
0 ignored issues
show
Documentation Bug introduced by
It seems like $credentials->getCredentialHash() can also be of type string. However, the property $credentialHash is declared as type null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
77
78
        // when the query succeeds,
79
        // we update the token value.
80
        $this->updateToken();
81
        
82
        if(isset($this->auth->params['authToken'])){
83
            $this->saveDeviceToken();
84
        }
85
    }
86
87
    /**
88
     * logout builder
89
     *
90
     * @param $token
91
     */
92
    public function logout($token)
93
    {
94
        // using the driver object we write the query builder statement.
95
        // we do the values of the query with the token that are sent.
96
        $query = $this->logoutQuery($token);
97
98
        // with query we bind the returned values to the params property of the auth object.
99
        // and so the auth object will make a final return with these values.
100
        $this->paramValues('logout',$query);
101
102
        //token updating as null
103
        if(isset($this->auth->params['authToken'])){
104
            if(!$this->deleteDeviceToken()){
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->deleteDeviceToken() of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
105
                $this->auth->params['status'] = 0;
106
                $this->auth->params['exception'] = 'logoutInternal';
107
                return false;
108
            }
109
        }
110
111
        if($this->auth->params['status']===0){
112
            $this->auth->params['exception'] = 'logoutException';
113
        }
114
    }
115
116
    /**
117
     * get user process
118
     *
119
     * @param AuthUserManager $manager
120
     */
121
    public function userProcess($manager)
122
    {
123
        return $this->userProcessQuery($manager);
124
    }
125
}
126