GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AloiaCmsUserProvider   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
eloc 31
c 1
b 0
f 0
dl 0
loc 93
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A createModel() 0 5 1
A retrieveByToken() 0 14 4
A validateCredentials() 0 5 1
A retrieveByCredentials() 0 11 2
A retrieveById() 0 11 2
A __construct() 0 4 1
A updateRememberToken() 0 4 1
1
<?php
2
3
namespace AloiaCms\Auth;
4
5
use Illuminate\Contracts\Auth\Authenticatable;
6
use Illuminate\Contracts\Auth\UserProvider;
7
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
8
9
class AloiaCmsUserProvider implements UserProvider
10
{
11
    /**
12
     * The hasher implementation.
13
     *
14
     * @var \Illuminate\Contracts\Hashing\Hasher
15
     */
16
    protected $hasher;
17
18
    /**
19
     * The user model.
20
     *
21
     * @var string
22
     */
23
    protected $model;
24
25
    /**
26
     * Create a new Aloia CMS user provider.
27
     *
28
     * @param  \Illuminate\Contracts\Hashing\Hasher  $hasher
29
     * @return void
30
     */
31
    public function __construct(HasherContract $hasher, string $model)
32
    {
33
        $this->hasher = $hasher;
34
        $this->model = $model;
35
    }
36
37
    public function retrieveById($identifier)
38
    {
39
        $user = $this
40
            ->createModel()
41
            ->findById($identifier);
42
43
        if ($user->exists()) {
44
            return $user;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $user returns the type AloiaCms\Models\Model which is incompatible with the return type mandated by Illuminate\Contracts\Aut...rovider::retrieveById() of Illuminate\Contracts\Auth\Authenticatable|null.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
45
        }
46
47
        return null;
48
    }
49
50
    public function retrieveByToken($identifier, $token)
51
    {
52
        $user = $this
53
            ->createModel()
54
            ->findById($identifier);
55
56
        if (!$user->exists()) {
57
            return null;
58
        }
59
60
        $rememberToken = $user->getRememberToken();
0 ignored issues
show
Bug introduced by
The method getRememberToken() does not exist on AloiaCms\Models\Model. It seems like you code against a sub-type of AloiaCms\Models\Model such as AloiaCms\Auth\User. ( Ignorable by Annotation )

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

60
        /** @scrutinizer ignore-call */ 
61
        $rememberToken = $user->getRememberToken();
Loading history...
61
62
        return $rememberToken && hash_equals($rememberToken, $token)
0 ignored issues
show
Bug Best Practice introduced by
The expression return $rememberToken &&... $token) ? $user : null also could return the type AloiaCms\Models\Model which is incompatible with the return type mandated by Illuminate\Contracts\Aut...ider::retrieveByToken() of Illuminate\Contracts\Auth\Authenticatable|null.
Loading history...
63
            ? $user : null;
64
    }
65
66
    public function updateRememberToken(Authenticatable $user, $token)
67
    {
68
        $user->setRememberToken($token);
69
        $user->save();
70
    }
71
72
    public function retrieveByCredentials(array $credentials)
73
    {
74
        $user = $this
75
            ->createModel()
76
            ->findById($credentials['email']);
77
78
        if ($user->exists()) {
79
            return $user;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $user returns the type AloiaCms\Models\Model which is incompatible with the return type mandated by Illuminate\Contracts\Aut...retrieveByCredentials() of Illuminate\Contracts\Auth\Authenticatable|null.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
80
        }
81
82
        return null;
83
    }
84
85
    public function validateCredentials(Authenticatable $user, array $credentials)
86
    {
87
        $plain = $credentials['password'];
88
89
        return $this->hasher->check($plain, $user->getAuthPassword());
90
    }
91
92
    /**
93
     * Create a new instance of the model.
94
     *
95
     * @return \AloiaCms\Models\Model
96
     */
97
    public function createModel()
98
    {
99
        $class = '\\'.ltrim($this->model, '\\');
100
101
        return new $class;
102
    }
103
}
104