Passed
Push — feature/settings-2fa ( d5cfe0...3c3c7f )
by Chris
30:52 queued 23:32
created

RememberDeviceTrait::getRememberDeviceKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Traits;
4
5
use Illuminate\Support\Str;
6
7
trait RememberDeviceTrait
8
{
9
    /**
10
     * The column name of the "remember device" token.
11
     *
12
     * @var string
13
     */
14
    protected $rememberDeviceTokenName = 'remember_device_token';
15
16
    /**
17
     * Get the token value for the "remember device" session.
18
     *
19
     * @return string|null
20
     */
21
    public function getRememberDeviceToken()
0 ignored issues
show
introduced by
Method \App\Traits\RememberDeviceTrait::getRememberDeviceToken() does not have return type hint for its return value but it should be possible to add it based on @return annotation "string|null".
Loading history...
22
    {
23
        if (! empty($this->getRememberDeviceTokenName())) {
24
            return (string) $this->{$this->getRememberDeviceTokenName()};
25
        }
26
    }
27
28
    /**
29
     * Set the token value for the "remember device" session.
30
     *
31
     * @param  string $value
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
32
     * @return void
33
     */
34
    public function setRememberDeviceToken($value)
1 ignored issue
show
introduced by
Method \App\Traits\RememberDeviceTrait::setRememberDeviceToken() does not have parameter type hint for its parameter $value but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \App\Traits\RememberDeviceTrait::setRememberDeviceToken() does not have return type hint for its return value but it should be possible to add it based on @return annotation "void".
Loading history...
Coding Style introduced by
Type hint "string" missing for $value
Loading history...
35
    {
36
        if (! empty($this->getRememberDeviceTokenName())) {
37
            $this->{$this->getRememberDeviceTokenName()} = $value;
38
        }
39
    }
40
41
    /**
42
     * Get the column name for the "remember device" token.
43
     *
44
     * @return string
45
     */
46
    public function getRememberDeviceTokenName()
0 ignored issues
show
introduced by
Method \App\Traits\RememberDeviceTrait::getRememberDeviceTokenName() does not have return type hint for its return value but it should be possible to add it based on @return annotation "string".
Loading history...
47
    {
48
        return $this->rememberDeviceTokenName;
49
    }
50
51
    /**
52
     * Refresh the "remember device" token for the User.
53
     *
54
     * @return void
55
     */
56
    public function cycleRememberDeviceToken()
0 ignored issues
show
introduced by
Method \App\Traits\RememberDeviceTrait::cycleRememberDeviceToken() does not have return type hint for its return value but it should be possible to add it based on @return annotation "void".
Loading history...
57
    {
58
        $this->setRememberDeviceToken(Str::random(60));
59
    }
60
61
    /**
62
     * Get a key to be used by a cookie for the
63
     * remember device token.
64
     *
65
     * @return string
66
     */
67
    public function getRememberDeviceKey(): string
68
    {
69
        return 'remember_device_'.sha1(static::class);
70
    }
71
}
72