PasswordReset   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 102
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A user() 0 8 1
A getTokenRepository() 0 4 1
A isExpired() 0 8 1
1
<?php namespace Arcanedev\LaravelAuth\Models;
2
3
use Arcanedev\Support\Database\Model;
4
5
/**
6
 * Class     PasswordReset
7
 *
8
 * @package  Arcanedev\LaravelAuth\Models
9
 * @author   ARCANEDEV <[email protected]>
10
 *
11
 * @property  string          email
12
 * @property  string          token
13
 * @property  \Carbon\Carbon  created_at
14
 *
15
 * @property  \Arcanedev\LaravelAuth\Models\User  $user
16
 */
17
class PasswordReset extends Model
18
{
19
    /* -----------------------------------------------------------------
20
     |  Properties
21
     | -----------------------------------------------------------------
22
     */
23
24
    /**
25
     * The attributes that should be hidden for arrays.
26
     *
27
     * @var array
28
     */
29
    protected $hidden  = ['token'];
30
31
    /**
32
     * Indicates if the model should be timestamped.
33
     *
34
     * @var bool
35
     */
36
    public $timestamps = false;
37
38
    /**
39
     * The attributes that should be mutated to dates.
40
     *
41
     * @var array
42
     */
43
    protected $dates   = [self::CREATED_AT];
44
45
    /* -----------------------------------------------------------------
46
     |  Constructor
47
     | -----------------------------------------------------------------
48
     */
49
50
    /**
51
     * Create a new Eloquent model instance.
52
     *
53
     * @param  array  $attributes
54
     */
55 6
    public function __construct(array $attributes = [])
56
    {
57 6
        $this->setConnection(null)
58 6
             ->setPrefix(null)
59 6
             ->setTable(
60 6
                 config('auth.passwords.users.table', 'password_resets')
61
             );
62
63 6
        parent::__construct($attributes);
64 6
    }
65
66
    /* -----------------------------------------------------------------
67
     |  Relationships
68
     | -----------------------------------------------------------------
69
     */
70
71
    /**
72
     * The user relationship.
73
     *
74
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
75
     */
76 3
    public function user()
77
    {
78 3
        return $this->belongsTo(
79 3
            config('laravel-auth.users.model', User::class),
80 3
            'email',
81 3
            'email'
82
        );
83
    }
84
85
    /* -----------------------------------------------------------------
86
     |  Getters & Setters
87
     | -----------------------------------------------------------------
88
     */
89
90
    /**
91
     * Get the token repository.
92
     *
93
     * @return \Illuminate\Auth\Passwords\TokenRepositoryInterface
94
     */
95 3
    public static function getTokenRepository()
96
    {
97 3
        return app('auth.password')->getRepository();
98
    }
99
100
    /* -----------------------------------------------------------------
101
     |  Check Methods
102
     | -----------------------------------------------------------------
103
     */
104
105
    /**
106
     * Check if the password reset was expired.
107
     *
108
     * @return bool
109
     */
110 3
    public function isExpired()
111
    {
112 3
        return $this->created_at->lt(
113 3
            $this->freshTimestamp()->subMinutes(
114 3
                config('auth.passwords.users.expire', 60)
115
            )
116
        );
117
    }
118
}
119