Passed
Push — task/laravel-breadcrumbs ( 3beccb...a96280 )
by Yonathan
10:46 queued 10s
created

RememberDeviceTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 7
eloc 13
c 3
b 1
f 0
dl 0
loc 67
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getRememberDeviceTokenName() 0 3 1
A getRememberDeviceToken() 0 4 2
A getRememberDeviceKey() 0 3 1
A cycleRememberDeviceToken() 0 7 1
A setRememberDeviceToken() 0 4 2
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 native 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
Coding Style introduced by
Type hint "string" missing for $value
Loading history...
introduced by
Method \App\Traits\RememberDeviceTrait::setRememberDeviceToken() does not have native 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 native return type hint for its return value but it should be possible to add it based on @return annotation "void".
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 native 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 native 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
        $timestamps = $this->timestamps;
60
        $this->timestamps = false;
0 ignored issues
show
Bug Best Practice introduced by
The property timestamps does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
61
        $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? ( Ignorable by Annotation )

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

61
        $this->/** @scrutinizer ignore-call */ 
62
               save();
Loading history...
62
        $this->timestamps = $timestamps;
63
    }
64
65
    /**
66
     * Get a key to be used by a cookie for the
67
     * remember device token.
68
     *
69
     * @return string
1 ignored issue
show
introduced by
Method \App\Traits\RememberDeviceTrait::getRememberDeviceKey() has useless @return annotation.
Loading history...
70
     */
71
    public function getRememberDeviceKey(): string
72
    {
73
        return 'remember_device_' . sha1(static::class);
74
    }
75
}
76