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.

UserConfirmation::generateConfirmationCode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php namespace Afrittella\BackProject\Traits;
2
/**
3
 * UserConfirmation Trait
4
 * checks if User model is confirmed
5
 *
6
 * @author Andrea Frittella <[email protected]>
7
*/
8
9
trait UserConfirmation
10
{
11
    protected $confirmation_field = 'confirmed';
12
    protected $confirmation_token_field = 'confirmation_code';
13
14
    public function confirm($code)
15
    {
16
    if ($this->{$this->confirmation_token_field} == $code && $this->isPendingConfirmation()) {
17
        $this->{$this->confirmation_token_field} = null;
18
        $this->{$this->confirmation_field} = 1;
19
        $this->save();
0 ignored issues
show
Bug introduced by
It seems like save() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
20
        return true;
21
    }
22
23
    return false;
24
    }
25
26
    public function isConfirmed()
27
    {
28
    return (bool) $this->{$this->confirmation_field};
29
    }
30
31
    public function hasConfirmationCode()
32
    {
33
    return !is_null($this->{$this->confirmation_token_field} );
34
    }
35
36
    public function isPendingConfirmation()
37
    {
38
    return !$this->isConfirmed() && $this->hasConfirmationCode();
39
    }
40
41
    public function getConfirmationField()
42
    {
43
    return $this->confirmation_field;
44
    }
45
46
    public function getConfirmationTokenField()
47
    {
48
    return $this->confirmation_token_field;
49
    }
50
51
    public function generateConfirmationCode()
52
    {
53
        return hash_hmac('sha256', str_random(40), config('app.key'));
54
    }
55
}
56